<!DOCTYPE html>
<!--[if IE 8]>    <html class="no-js lt-ie9" lang="en"> <![endif]-->
<!--[if gt IE 8]><!-->
<html style="" class=" js no-touch svg inlinesvg svgclippaths no-ie8compat js no-touch svg inlinesvg svgclippaths no-ie8compat" lang="en"><!--<![endif]--><head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
        <!-- Meta -->
        <meta charset="utf-8">

        <!-- Set the viewport width to device width for mobile -->
        <meta name="viewport" content="width=device-width, initial-scale=1.0">

        <title>Action Helpers - Zend_Controller - Zend Framework</title>

        <!-- CSS, feeds and favicon -->
        <link href="zend.controller.actionhelpers_files/foundation.css" media="screen" rel="stylesheet" type="text/css">
        <link href="zend.controller.actionhelpers_files/app.css" media="screen" rel="stylesheet" type="text/css">
        <link href="http://framework.zend.com/blog/feed-rss.xml" rel="alternate" type="application/rss+xml" title="Zend Framework Blog RSS Feed">
        <link href="http://framework.zend.com/blog/feed-atom.xml" rel="alternate" type="application/atom+xml" title="Zend Framework Blog Atom Feed">
        <link href="http://framework.zend.com/security/feed/" rel="alternate" type="application/rss+xml" title="Zend Framework Security Advisories">
        <link href="http://framework.zend.com/images/favicon.ico" rel="shortcut icon" type="image/vnd.microsoft.icon">

        <!-- JavaScript -->
        <script type="text/javascript" src="zend.controller.actionhelpers_files/modernizr.js"></script>
        
        <!-- IE Fix for HTML5 Tags -->
        <!--[if lt IE 9]>
        <script src="http://html5shiv.googlecode.com/svn/trunk/html5.js"></script>
        <![endif]-->
    <script src="zend.controller.actionhelpers_files/embed.js" async="" type="text/javascript"></script><script charset="UTF-8" async="" src="zend.controller.actionhelpers_files/alfie.js"></script><script src="zend.controller.actionhelpers_files/ga.js" async="" type="text/javascript"></script><script src="zend.controller.actionhelpers_files/mTag.js" charset="iso-8859-1" type="text/javascript"></script></head>
    <body id="manual">

        <!-- Header -->
        <header id="header" class="row">

            <!-- Logo -->
            <div class="three mobile-two columns" id="logo">
                <h1>
                    <a href="http://framework.zend.com/" title="">
                        <img src="zend.controller.actionhelpers_files/logo.png" alt="Zend Framework" height="41" width="173">
                    </a>
                </h1>
            </div>

            <!-- Menu -->
            <div class="six mobile-two columns" id="menu">
                <nav class="top-bar">
                    <ul>
                        <li class="name show-for-small">Menu</li>
                        <li class="toggle-topbar show-for-small"><a href="#"></a></li>
                        <li><a href="http://framework.zend.com/about/">About</a></li>
                        <li class="active"><a href="http://framework.zend.com/learn/">Learn</a></li>
                        <li><a href="http://framework.zend.com/downloads">Get Started</a></li>
                        <li><a href="http://framework.zend.com/participate/">Participate</a></li>
                        <li class="show-for-small">
                            <!-- Search form for small screens -->
                            <form method="get" action="//www.google.com/search" target="_blank">
                                <input name="q" maxlength="255" placeholder="Search in the site" type="text">
                                <input name="sitesearch" value="framework.zend.com" type="hidden">
                            </form>
                        </li>
                    </ul>
                </nav>
            </div>

            <!-- Search form -->
            <form method="get" action="//www.google.com/search" target="_blank" class="three columns hide-for-small">
                <input name="q" maxlength="255" placeholder="Search in the site" type="text">
                <input name="sitesearch" value="framework.zend.com" type="hidden">
            </form>

            <!-- Link to Github -->
                    </header>
        
        <div id="top-header-shadow"></div>

                    <div class="show-for-small" id="navigation-button">
                <a href="#navigation" class="secondary round button">…</a>
            </div>
            <div class="row">
                <!-- Navigation -->
                <nav id="navigation" class="three columns">
                    <div id="selectversion">
    Select a version:
    <select onchange="javascript:location.href='/manual/'+this.value+'/en/';">
        <option>2.1</option><option>2.0</option><option>1.9</option><option>1.8</option><option>1.7</option><option>1.6</option><option>1.5</option><option selected="selected">1.12</option><option>1.11</option><option>1.10</option><option>1.0</option>    </select>
</div>
<h1><a href="http://framework.zend.com/manual/1.12/en/manual.html">Table Of Contents</a></h1><ul>
<li class="header up"><a href="http://framework.zend.com/manual/1.12/en/zend.controller.html">Zend_Controller</a></li><ul>
<li><a href="http://framework.zend.com/manual/1.12/en/zend.controller.actionhelpers.html#zend.controller.actionhelper.introduction">Introduction</a></li><li><a href="http://framework.zend.com/manual/1.12/en/zend.controller.actionhelpers.html#zend.controller.actionhelper.initialization">Helper Initialization</a></li><li><a href="http://framework.zend.com/manual/1.12/en/zend.controller.actionhelpers.html#zend.controller.actionhelper.broker">The Helper Broker</a></li><li><a href="http://framework.zend.com/manual/1.12/en/zend.controller.actionhelpers.html#zend.controller.actionhelper.stockhelpers">Built-in Action Helpers</a><ul><li><a href="http://framework.zend.com/manual/1.12/en/zend.controller.actionhelpers.html#zend.controller.actionhelpers.actionstack">ActionStack</a></li><li><a href="http://framework.zend.com/manual/1.12/en/zend.controller.actionhelpers.html#zend.controller.actionhelpers.autocomplete">AutoComplete</a></li><li><a href="http://framework.zend.com/manual/1.12/en/zend.controller.actionhelpers.html#zend.controller.actionhelpers.contextswitch">ContextSwitch and AjaxContext</a></li><li><a href="http://framework.zend.com/manual/1.12/en/zend.controller.actionhelpers.html#zend.controller.actionhelpers.flashmessenger">FlashMessenger</a></li><li><a href="http://framework.zend.com/manual/1.12/en/zend.controller.actionhelpers.html#zend.controller.actionhelpers.json">JSON</a></li><li><a href="http://framework.zend.com/manual/1.12/en/zend.controller.actionhelpers.html#zend.controller.actionhelpers.redirector">Redirector</a></li><li><a href="http://framework.zend.com/manual/1.12/en/zend.controller.actionhelpers.html#zend.controller.actionhelpers.viewrenderer">ViewRenderer</a></li></ul></li><li><a href="http://framework.zend.com/manual/1.12/en/zend.controller.actionhelpers.html#zend.controller.actionhelper.writingyourown">Writing Your Own Helpers</a></li></ul>
</ul>
<h1>Previous topic</h1><p class="topless"><a href="http://framework.zend.com/manual/1.12/en/zend.controller.action.html" title="previous chapter">Action Controllers</a></p><h1>Next topic</h1><p class="topless"><a href="http://framework.zend.com/manual/1.12/en/zend.controller.response.html" title="next chapter">The Response Object</a></p>                </nav>

                <!-- Content -->
                <div id="content" class="nine columns" role="main">
                    <div class="related hide-on-print"><ul><li class="prev"><a href="http://framework.zend.com/manual/1.12/en/zend.controller.action.html">Action Controllers</a></li><li class="next"><a href="http://framework.zend.com/manual/1.12/en/zend.controller.response.html">The Response Object</a></li></ul></div><div id="zend.controller.actionhelpers" class="section"><div class="info"><h1 class="title">Action Helpers</h1></div>
    

    <div class="section" id="zend.controller.actionhelper.introduction" name="zend.controller.actionhelper.introduction"><div class="info"><h2>Introduction</h2></div>
        

        <p class="para">
            Action Helpers allow developers to inject runtime and/or on-demand
            functionality into any Action Controllers that extend
            <span class="classname">Zend_Controller_Action</span>. Action Helpers aim to minimize the
            necessity to extend the abstract Action Controller in order to
            inject common Action Controller functionality.
        </p>

        <p class="para">
            There are a number of ways to use Action Helpers. Action Helpers
            employ the use of a brokerage system, similar to the types of
            brokerage you see in <a href="http://framework.zend.com/manual/1.12/en/zend.view.helpers.html" class="link">Zend_View_Helper</a>, and that
            of <a href="http://framework.zend.com/manual/1.12/en/zend.controller.plugins.html" class="link">Zend_Controller_Plugin</a>.
            Action Helpers (like <span class="classname">Zend_View_Helper</span>) may be
            loaded and called on demand, or they may be instantiated at
            request time (bootstrap) or action controller creation time
            ( <span class="methodname">init()</span>). To understand this more fully, please see the usage
            section below.
        </p>
    </div>

    <div class="section" id="zend.controller.actionhelper.initialization" name="zend.controller.actionhelper.initialization"><div class="info"><h2>Helper Initialization</h2></div>
        

        <p class="para">
            A helper can be initialized in several different ways, based on
            your needs as well as the functionality of that helper.
        </p>

        <p class="para">
            The helper broker is stored as the <var class="varname">$_helper</var> member of
            <span class="classname">Zend_Controller_Action</span>; use the broker to retrieve or
            call on helpers. Some methods for doing so include:
        </p>

        <ul class="itemizedlist"><li class="listitem">
                <p class="para">
                    Explicitly using  <span class="methodname">getHelper()</span>. Simply pass it a
                    name, and a helper object is returned:
                </p>

                <div class="programlisting php"><div class="phpcode"><div class="php" style="font-family: monospace;"><ol><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #0000ff;">$flashMessenger</span> = <span style="color: #0000ff;">$this</span>-&gt;_helper-&gt;<span style="color: #006600;">getHelper</span><span style="color: #66cc66;">(</span><span style="color: #ff0000;">'FlashMessenger'</span><span style="color: #66cc66;">)</span>;</div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #0000ff;">$flashMessenger</span>-&gt;<span style="color: #006600;">addMessage</span><span style="color: #66cc66;">(</span><span style="color: #ff0000;">'We did something in the last request'</span><span style="color: #66cc66;">)</span>;</div></li></ol></div></div></div>

            </li>

            <li class="listitem">
                <p class="para">
                    Use the helper broker's  <span class="methodname">__get()</span> functionality
                    and retrieve the helper as if it were a member property of
                    the broker:
                </p>

                <div class="programlisting php"><div class="phpcode"><div class="php" style="font-family: monospace;"><ol><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #0000ff;">$flashMessenger</span> = <span style="color: #0000ff;">$this</span>-&gt;_helper-&gt;<span style="color: #006600;">FlashMessenger</span>;</div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #0000ff;">$flashMessenger</span>-&gt;<span style="color: #006600;">addMessage</span><span style="color: #66cc66;">(</span><span style="color: #ff0000;">'We did something in the last request'</span><span style="color: #66cc66;">)</span>;</div></li></ol></div></div></div>

            </li>

            <li class="listitem">
                <p class="para">
                    Finally, most action helpers implement the method
                     <span class="methodname">direct()</span> which will call a specific, default
                    method in the helper. In the example of the
                    <em class="emphasis">FlashMessenger</em>, it calls
                     <span class="methodname">addMessage()</span>:
                </p>

                <div class="programlisting php"><div class="phpcode"><div class="php" style="font-family: monospace;"><ol><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #0000ff;">$this</span>-&gt;_helper-&gt;<span style="color: #006600;">FlashMessenger</span><span style="color: #66cc66;">(</span><span style="color: #ff0000;">'We did something in the last request'</span><span style="color: #66cc66;">)</span>;</div></li></ol></div></div></div>

            </li>
        </ul><blockquote><p><b class="note">Note</b>: 
            All of the above examples are functionally equivalent.<br></p></blockquote>

        <p class="para">
            You may also instantiate helpers explicitly. You may wish to do this
            if using the helper outside of an action controller, or if you wish
            to pass a helper to the helper broker for use by any action.
            Instantiation is as per any other <acronym class="acronym">PHP</acronym> class.
        </p>
    </div>

    <div class="section" id="zend.controller.actionhelper.broker" name="zend.controller.actionhelper.broker"><div class="info"><h2>The Helper Broker</h2></div>
        

        <p class="para">
            <span class="classname">Zend_Controller_Action_HelperBroker</span> handles the details
            of registering helper objects and helper paths, as well as
            retrieving helpers on-demand.
        </p>

        <p class="para">
            To register a helper with the broker, use  <span class="methodname">addHelper()</span>:
        </p>

        <div class="programlisting php"><div class="phpcode"><div class="php" style="font-family: monospace;"><ol><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">Zend_Controller_Action_HelperBroker::<span style="color: #006600;">addHelper</span><span style="color: #66cc66;">(</span><span style="color: #0000ff;">$helper</span><span style="color: #66cc66;">)</span>;</div></li></ol></div></div></div>


        <p class="para">
            Of course, instantiating and passing helpers to the broker is a bit
            time and resource intensive, so two methods exists to automate
            things slightly:  <span class="methodname">addPrefix()</span> and
             <span class="methodname">addPath()</span>.
        </p>

        <ul class="itemizedlist"><li class="listitem">
                <p class="para">
                     <span class="methodname">addPrefix()</span> takes a class prefix and uses it
                    to determine a path where helper classes have been defined.
                    It assumes the prefix follows Zend Framework class naming
                    conventions.
                </p>

                <div class="programlisting php"><div class="phpcode"><div class="php" style="font-family: monospace;"><ol><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #808080; font-style: italic;">// Add helpers prefixed with My_Action_Helpers in My/Action/Helpers/</span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">Zend_Controller_Action_HelperBroker::<span style="color: #006600;">addPrefix</span><span style="color: #66cc66;">(</span><span style="color: #ff0000;">'My_Action_Helpers'</span><span style="color: #66cc66;">)</span>;</div></li></ol></div></div></div>

            </li>

            <li class="listitem">
                <p class="para">
                     <span class="methodname">addPath()</span> takes a directory as its first
                    argument and a class prefix as the second argument
                    (defaulting to '<span class="classname">Zend_Controller_Action_Helper</span>').
                    This allows you to map your own class prefixes to specific directories.
                </p>

                <div class="programlisting php"><div class="phpcode"><div class="php" style="font-family: monospace;"><ol><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #808080; font-style: italic;">// Add helpers prefixed with Helper in Plugins/Helpers/</span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">Zend_Controller_Action_HelperBroker::<span style="color: #006600;">addPath</span><span style="color: #66cc66;">(</span><span style="color: #ff0000;">'./Plugins/Helpers'</span>,</div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 
&nbsp; &nbsp;<span style="color: #ff0000;">'Helper'</span><span style="color: #66cc66;">)</span>;</div></li></ol></div></div></div>

            </li>
        </ul><p class="para">
            Since these methods are static, they may be called at any point in
            the controller chain in order to dynamically add helpers as needed.
        </p>

        <p class="para">
            Internally, the helper broker uses <a href="http://framework.zend.com/manual/1.12/en/zend.loader.pluginloader.html" class="link">a PluginLoader
                instance</a> to maintain paths. You can retrieve the
            PluginLoader using the static method  <span class="methodname">getPluginLoader()</span>,
            or, alternately, inject a custom PluginLoader instance using
             <span class="methodname">setPluginLoader()</span>.
        </p>

        <p class="para">
            To determine if a helper exists in the helper broker, use
             <span class="methodname">hasHelper($name)</span>, where <var class="varname">$name</var> is the short
            name of the helper (minus the prefix):
        </p>

        <div class="programlisting php"><div class="phpcode"><div class="php" style="font-family: monospace;"><ol><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #808080; font-style: italic;">// Check if 'redirector' helper is registered with the broker:</span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #b1b100;">if</span> <span style="color: #66cc66;">(</span>Zend_Controller_Action_HelperBroker::<span style="color: #006600;">hasHelper</span><span style="color: #66cc66;">(</span><span style="color: #ff0000;">'redirector'</span><span style="color: #66cc66;">)</span><span style="color: #66cc66;">)</span> <span style="color: #66cc66;">{</span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <a href="http://www.php.net/echo"><span style="color: #000066;">echo</span></a> <span style="color: #ff0000;">'Redirector helper registered'</span>;</div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #66cc66;">}</span></div></li></ol></div></div></div>


        <p class="para">
            There are also two static methods for retrieving helpers from the helper
            broker:  <span class="methodname">getExistingHelper()</span> and
             <span class="methodname">getStaticHelper()</span>.
             <span class="methodname">getExistingHelper()</span>
            will retrieve a helper only if it has previously been invoked by or
            explicitly registered with the helper broker; it will throw an
            exception if not.  <span class="methodname">getStaticHelper()</span> does the same as
             <span class="methodname">getExistingHelper()</span>, but will attempt to instantiate
            the helper if has not yet been registered with the helper stack.
             <span class="methodname">getStaticHelper()</span> is a good choice for retrieving
            helpers which you wish to configure.
        </p>

        <p class="para">
            Both methods take a single argument, <var class="varname">$name</var>, which is
            the short name of the helper (minus the prefix).
        </p>

        <div class="programlisting php"><div class="phpcode"><div class="php" style="font-family: monospace;"><ol><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #808080; font-style: italic;">// Check if 'redirector' helper is registered with the broker, and fetch:</span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #b1b100;">if</span> <span style="color: #66cc66;">(</span>Zend_Controller_Action_HelperBroker::<span style="color: #006600;">hasHelper</span><span style="color: #66cc66;">(</span><span style="color: #ff0000;">'redirector'</span><span style="color: #66cc66;">)</span><span style="color: #66cc66;">)</span> <span style="color: #66cc66;">{</span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #0000ff;">$redirector</span> =</div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; Zend_Controller_Action_HelperBroker::<span style="color: #006600;">getExistingHelper</span><span style="color: #66cc66;">(</span><span style="color: #ff0000;">'redirector'</span><span style="color: #66cc66;">)</span>;</div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #66cc66;">}</span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #808080; font-style: italic;">// Or, simply retrieve it, not worrying about whether or not it was</span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #808080; font-style: italic;">// previously registered:</span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #0000ff;">$redirector</span> =</div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; Zend_Controller_Action_HelperBroker::<span style="color: #006600;">getStaticHelper</span><span style="color: #66cc66;">(</span><span style="color: #ff0000;">'redirector'</span><span style="color: #66cc66;">)</span>;</div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #66cc66;">}</span></div></li></ol></div></div></div>


        <p class="para">
            Finally, to delete a registered helper from the broker, use
             <span class="methodname">removeHelper($name)</span>, where <var class="varname">$name</var> is the
            short name of the helper (minus the prefix):
        </p>

        <div class="programlisting php"><div class="phpcode"><div class="php" style="font-family: monospace;"><ol><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #808080; font-style: italic;">// Conditionally remove the 'redirector' helper from the broker:</span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #b1b100;">if</span> <span style="color: #66cc66;">(</span>Zend_Controller_Action_HelperBroker::<span style="color: #006600;">hasHelper</span><span style="color: #66cc66;">(</span><span style="color: #ff0000;">'redirector'</span><span style="color: #66cc66;">)</span><span style="color: #66cc66;">)</span> <span style="color: #66cc66;">{</span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; Zend_Controller_Action_HelperBroker::<span style="color: #006600;">removeHelper</span><span style="color: #66cc66;">(</span><span style="color: #ff0000;">'redirector'</span><span style="color: #66cc66;">)</span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #66cc66;">}</span></div></li></ol></div></div></div>

    </div>

    <div class="section" id="zend.controller.actionhelper.stockhelpers" name="zend.controller.actionhelper.stockhelpers"><div class="info"><h2>Built-in Action Helpers</h2></div>
        

        <p class="para">
            Zend Framework includes several action helpers by default:
            <em class="emphasis">AutoComplete</em> for automating responses for <acronym class="acronym">AJAX</acronym>
            autocompletion; <em class="emphasis">ContextSwitch</em> and
            <em class="emphasis">AjaxContext</em> for serving alternate response formats for
            your actions; a <em class="emphasis">FlashMessenger</em> for handling session flash
            messages; <em class="emphasis">Json</em> for encoding and sending <acronym class="acronym">JSON</acronym>
            responses; a <em class="emphasis">Redirector</em>, to provide different
            implementations for redirecting to internal and external pages from
            your application; and a <em class="emphasis">ViewRenderer</em> to automate the
            process of setting up the view object in your controllers and
            rendering views.
        </p>

        <div class="section" id="zend.controller.actionhelpers.actionstack" name="zend.controller.actionhelpers.actionstack"><div class="info"><h3>ActionStack</h3></div>
    

    <p class="para">
        The <em class="emphasis">ActionStack</em> helper allows you to push requests to the
        <a href="http://framework.zend.com/manual/1.12/en/zend.controller.plugins.html#zend.controller.plugins.standard.actionstack" class="link">ActionStack</a>
        front controller plugin, effectively helping you create a queue of
        actions to execute during the request. The helper allows you to add
        actions either by specifying new request objects or
        action - controller - module sets.
    </p>

    <blockquote><p><b class="note">Note</b>: <span class="info"><b>Invoking ActionStack Helper Initializes the ActionStack Plugin</b><br></span>
        

        
            Invoking the <em class="emphasis">ActionStack</em> helper implicitly registers
            the <em class="emphasis">ActionStack</em> plugin -- which means you do not need
            to explicitly register the <em class="emphasis">ActionStack</em> plugin to use
            this functionality.
        <br></p></blockquote>

    <div class="example"><div class="info"><p><b>Example #1 Adding a Task Using Action, Controller and Module Names</b></p></div>
        

        <div class="example-contents"><p>
            Often, it's simplest to simply specify the action, controller, and
            module (and optional request parameters), much as you would when
            calling  <span class="methodname">Zend_Controller_Action::_forward()</span>:
        </p></div>

        <div class="programlisting php"><div class="phpcode"><div class="php" style="font-family: monospace;"><ol><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #000000; font-weight: bold;">class</span> FooController <span style="color: #000000; font-weight: bold;">extends</span> Zend_Controller_Action</div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #66cc66;">{</span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> barAction<span style="color: #66cc66;">(</span><span style="color: #66cc66;">)</span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #66cc66;">{</span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080; font-style: italic;">// Add two actions to the stack</span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080; font-style: italic;">// Add call to /foo/baz/bar/baz</span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080; font-style: italic;">// (FooController::bazAction() with request var bar == baz)</span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000ff;">$this</span>-&gt;_helper-&gt;<span style="color: #006600;">actionStack</span><span style="color: #66cc66;">(</span><span style="color: #ff0000;">'baz'</span>,</div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #ff0000;">'foo'</span>,</div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #ff0000;">'default'</span>,</div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <a href="http://www.php.net/array"><span style="color: #000066;">array</span></a><span style="color: #66cc66;">(</span><span style="color: #ff0000;">'bar'</span> =&gt; <span style="color: #ff0000;">'baz'</span><span style="color: #66cc66;">)</span><span style="color: #66cc66;">)</span>;</div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080; font-style: italic;">// Add call to /bar/bat</span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080; font-style: italic;">// (BarController::batAction())</span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000ff;">$this</span>-&gt;_helper-&gt;<span style="color: #006600;">actionStack</span><span style="color: #66cc66;">(</span><span style="color: #ff0000;">'bat'</span>, <span style="color: #ff0000;">'bar'</span><span style="color: #66cc66;">)</span>;</div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #66cc66;">}</span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #66cc66;">}</span></div></li></ol></div></div></div>

    </div>

    <div class="example"><div class="info"><p><b>Example #2 Adding a Task Using a Request Object</b></p></div>
        

        <div class="example-contents"><p>
            Sometimes the <acronym class="acronym">OOP</acronym> nature of a request object makes most sense; you
            can pass such an object to the <em class="emphasis">ActionStack</em> helper as
            well.
        </p></div>

        <div class="programlisting php"><div class="phpcode"><div class="php" style="font-family: monospace;"><ol><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #000000; font-weight: bold;">class</span> FooController <span style="color: #000000; font-weight: bold;">extends</span> Zend_Controller_Action</div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #66cc66;">{</span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> barAction<span style="color: #66cc66;">(</span><span style="color: #66cc66;">)</span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #66cc66;">{</span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080; font-style: italic;">// Add two actions to the stack</span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080; font-style: italic;">// Add call to /foo/baz/bar/baz</span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080; font-style: italic;">// (FooController::bazAction() with request var bar == baz)</span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000ff;">$request</span> = clone <span style="color: #0000ff;">$this</span>-&gt;<span style="color: #006600;">getRequest</span><span style="color: #66cc66;">(</span><span style="color: #66cc66;">)</span>;</div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080; font-style: italic;">// Don't set controller or module; use current values</span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000ff;">$request</span>-&gt;<span style="color: #006600;">setActionName</span><span style="color: #66cc66;">(</span><span style="color: #ff0000;">'baz'</span><span style="color: #66cc66;">)</span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; -&gt;<span style="color: #006600;">setParams</span><span style="color: #66cc66;">(</span><a href="http://www.php.net/array"><span style="color: #000066;">array</span></a><span style="color: #66cc66;">(</span><span style="color: #ff0000;">'bar'</span> =&gt; <span style="color: #ff0000;">'baz'</span><span style="color: #66cc66;">)</span><span style="color: #66cc66;">)</span>;</div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000ff;">$this</span>-&gt;_helper-&gt;<span style="color: #006600;">actionStack</span><span style="color: #66cc66;">(</span><span style="color: #0000ff;">$request</span><span style="color: #66cc66;">)</span>;</div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080; font-style: italic;">// Add call to /bar/bat</span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080; font-style: italic;">// (BarController::batAction())</span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000ff;">$request</span> = clone <span style="color: #0000ff;">$this</span>-&gt;<span style="color: #006600;">getRequest</span><span style="color: #66cc66;">(</span><span style="color: #66cc66;">)</span>;</div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080; font-style: italic;">// don't set module; use current value</span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000ff;">$request</span>-&gt;<span style="color: #006600;">setActionName</span><span style="color: #66cc66;">(</span><span style="color: #ff0000;">'bat'</span><span style="color: #66cc66;">)</span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; -&gt;<span style="color: #006600;">setControllerName</span><span style="color: #66cc66;">(</span><span style="color: #ff0000;">'bar'</span><span style="color: #66cc66;">)</span>;</div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000ff;">$this</span>-&gt;_helper-&gt;<span style="color: #006600;">actionStack</span><span style="color: #66cc66;">(</span><span style="color: #0000ff;">$request</span><span style="color: #66cc66;">)</span>;</div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #66cc66;">}</span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #66cc66;">}</span></div></li></ol></div></div></div>

    </div>
</div>
        <div class="section" id="zend.controller.actionhelpers.autocomplete" name="zend.controller.actionhelpers.autocomplete"><div class="info"><h3>AutoComplete</h3></div>
    

    <p class="para">
        Many <acronym class="acronym">AJAX</acronym> javascript libraries offer functionality for providing
        autocompletion whereby a selectlist of potentially matching results is
        displayed as the user types. The <em class="emphasis">AutoComplete</em> helper aims
        to simplify returning acceptable responses to such methods.
    </p>

    <p class="para">
        Since not all JS libraries implement autocompletion in the same way, the
        <em class="emphasis">AutoComplete</em> helper provides some abstract base
        functionality necessary to many libraries, and concrete implementations
        for individual libraries. Return types are generally either <acronym class="acronym">JSON</acronym> arrays
        of strings, <acronym class="acronym">JSON</acronym> arrays of arrays (with each member array being an
        associative array of metadata used to create the selectlist), or <acronym class="acronym">HTML</acronym>.
    </p>

    <p class="para">
        Basic usage for each implementation is the same:
    </p>

   <div class="programlisting php"><div class="phpcode"><div class="php" style="font-family: monospace;"><ol><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #000000; font-weight: bold;">class</span> FooController <span style="color: #000000; font-weight: bold;">extends</span> Zend_Controller_Action</div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #66cc66;">{</span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> barAction<span style="color: #66cc66;">(</span><span style="color: #66cc66;">)</span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #66cc66;">{</span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080; font-style: italic;">// Perform some logic...</span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080; font-style: italic;">// Encode and send response;</span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000ff;">$this</span>-&gt;_helper-&gt;<span style="color: #006600;">autoCompleteDojo</span><span style="color: #66cc66;">(</span><span style="color: #0000ff;">$data</span><span style="color: #66cc66;">)</span>;</div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080; font-style: italic;">// Or explicitly:</span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000ff;">$response</span> = <span style="color: #0000ff;">$this</span>-&gt;_helper-&gt;<span style="color: #006600;">autoCompleteDojo</span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; -&gt;<span style="color: #006600;">sendAutoCompletion</span><span style="color: #66cc66;">(</span><span style="color: #0000ff;">$data</span><span style="color: #66cc66;">)</span>;</div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080; font-style: italic;">// Or simply prepare autocompletion response:</span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000ff;">$response</span> = <span style="color: #0000ff;">$this</span>-&gt;_helper-&gt;<span style="color: #006600;">autoCompleteDojo</span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; -&gt;<span style="color: #006600;">prepareAutoCompletion</span><span style="color: #66cc66;">(</span><span style="color: #0000ff;">$data</span><span style="color: #66cc66;">)</span>;</div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #66cc66;">}</span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #66cc66;">}</span></div></li></ol></div></div></div>


    <p class="para">
        By default, autocompletion does the following:
    </p>

    <ul class="itemizedlist"><li class="listitem"><p class="para">Disables layouts and ViewRenderer.</p></li>
        <li class="listitem"><p class="para">Sets appropriate response headers.</p></li>

        <li class="listitem">
            <p class="para">Sets response body with encoded or formatted autocompletion data.</p>
        </li>

        <li class="listitem"><p class="para">Sends response.</p></li>
    </ul><p class="para">
        Available methods of the helper include:
    </p>

    <ul class="itemizedlist"><li class="listitem">
            <p class="para">
                 <span class="methodname">disableLayouts()</span> can be used to disable layouts and
                the ViewRenderer. Typically, this is called within
                 <span class="methodname">prepareAutoCompletion()</span>.
            </p>
        </li>

        <li class="listitem">
            <p class="para">
                 <span class="methodname">encodeJson($data, $keepLayouts = false)</span> will encode
                data to <acronym class="acronym">JSON</acronym>, optionally enabling or disabling layouts.
                Typically, this is called within
                 <span class="methodname">prepareAutoCompletion()</span>.
            </p>
        </li>

        <li class="listitem">
            <p class="para">
                 <span class="methodname">prepareAutoCompletion($data, $keepLayouts = false)</span>
                is used to prepare data in the response format necessary for the
                concrete implementation, optionally enabling or disabling
                layouts. The return value will vary based on the implementation.
            </p>
        </li>

        <li class="listitem">
            <p class="para">
                 <span class="methodname">sendAutoCompletion($data, $keepLayouts = false)</span>
                is used to send data in the response format necessary for the
                concrete implementation. It calls
                 <span class="methodname">prepareAutoCompletion()</span>, and then sends the
                response.
            </p>
        </li>

        <li class="listitem">
            <p class="para">
                 <span class="methodname">direct($data, $sendNow = true, $keepLayouts =
                    false)</span> is used when calling the helper as a method of
                the helper broker. The <var class="varname">$sendNow</var> flag is used to
                determine whether to call  <span class="methodname">sendAutoCompletion()</span> or
                 <span class="methodname">prepareAutoCompletion()</span>, respectively.
            </p>
        </li>
    </ul><p class="para">
        Currently, <em class="emphasis">AutoComplete</em> supports the Dojo and Scriptaculous
        <acronym class="acronym">AJAX</acronym> libraries.
    </p>

    <div class="section" id="zend.controller.actionhelpers.autocomplete.dojo" name="zend.controller.actionhelpers.autocomplete.dojo"><div class="info"><h4>AutoCompletion with Dojo</h4></div>
        

        <p class="para">
            Dojo does not have an AutoCompletion widget per se, but has two
            widgets that can perform AutoCompletion: ComboBox and
            FilteringSelect. In both cases, they require a data store that
            implements the QueryReadStore; for more information on these topics, see the <a href="http://dojotoolkit.org/reference-guide/dojo/data.html" class="link external">» dojo.data</a>
            documentation.
        </p>

        <p class="para">
            In Zend Framework, you can pass a simple indexed array to the
            AutoCompleteDojo helper, and it will return a <acronym class="acronym">JSON</acronym> response suitable
            for use with such a store:
        </p>

        <div class="programlisting php"><div class="phpcode"><div class="php" style="font-family: monospace;"><ol><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #808080; font-style: italic;">// within a controller action:</span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #0000ff;">$this</span>-&gt;_helper-&gt;<span style="color: #006600;">autoCompleteDojo</span><span style="color: #66cc66;">(</span><span style="color: #0000ff;">$data</span><span style="color: #66cc66;">)</span>;</div></li></ol></div></div></div>


        <div class="example"><div class="info"><p><b>Example #3 AutoCompletion with Dojo Using Zend MVC</b></p></div>
            

            <div class="example-contents"><p>
                AutoCompletion with Dojo via the Zend <acronym class="acronym">MVC</acronym> requires several
                things: generating a form object for the ComboBox on which you
                want AutoCompletion, a controller action for serving the
                AutoCompletion results, creating a custom QueryReadStore to connect
                to the AutoCompletion action, and generation of the javascript
                to use to initialize AutoCompletion on the server side.
            </p></div>

            <div class="example-contents"><p>
                First, let's look at the javascript necessary. Dojo offers a
                complete framework for creating <acronym class="acronym">OOP</acronym> javascript, much as Zend
                Framework does for <acronym class="acronym">PHP</acronym>. Part of that is the ability to create
                pseudo-namespaces using the directory hierarchy. We'll create a
                'custom' directory at the same level as the Dojo directory
                that's part of the Dojo distribution. Inside that directory,
                we'll create a javascript file, <var class="filename">TestNameReadStore.js</var>, with the
                following contents:
            </p></div>

            <div class="programlisting javascript"><div class="javascriptcode"><div class="javascript" style="font-family: monospace;"><ol><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">dojo.<span style="color: #006600;">provide</span><span style="color: #66cc66;">(</span><span style="color: #3366CC;">"custom.TestNameReadStore"</span><span style="color: #66cc66;">)</span>;</div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">dojo.<span style="color: #006600;">declare</span><span style="color: #66cc66;">(</span><span style="color: #3366CC;">"custom.TestNameReadStore"</span>, dojox.<span style="color: #006600;">data</span>.<span style="color: #006600;">QueryReadStore</span>, <span style="color: #66cc66;">{</span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; fetch:<span style="color: #003366; font-weight: bold;">function</span> <span style="color: #66cc66;">(</span>request<span style="color: #66cc66;">)</span> <span style="color: #66cc66;">{</span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; request.<span style="color: #006600;">serverQuery</span> = <span style="color: #66cc66;">{</span> test:request.<span style="color: #006600;">query</span>.<span style="color: #000066;">name</span> <span style="color: #66cc66;">}</span>;</div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">return</span> <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #006600;">inherited</span><span style="color: #66cc66;">(</span><span style="color: #3366CC;">"fetch"</span>, arguments<span style="color: #66cc66;">)</span>;</div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #66cc66;">}</span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #66cc66;">}</span><span style="color: #66cc66;">)</span>;</div></li></ol></div></div></div>


            <div class="example-contents"><p>
                This class is simply an extension of Dojo's own QueryReadStore,
                which is itself an abstract class. We simply define a method by
                which to request, and assigning it to the 'test' element.
            </p></div>

            <div class="example-contents"><p>
                Next, let's create the form element for which we want
                AutoCompletion:
            </p></div>

            <div class="programlisting php"><div class="phpcode"><div class="php" style="font-family: monospace;"><ol><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #000000; font-weight: bold;">class</span> TestController <span style="color: #000000; font-weight: bold;">extends</span> Zend_Controller_Action</div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #66cc66;">{</span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; protected <span style="color: #0000ff;">$_form</span>;</div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> getForm<span style="color: #66cc66;">(</span><span style="color: #66cc66;">)</span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #66cc66;">{</span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">if</span> <span style="color: #66cc66;">(</span><span style="color: #000000; font-weight: bold;">null</span> === <span style="color: #0000ff;">$this</span>-&gt;_form<span style="color: #66cc66;">)</span> <span style="color: #66cc66;">{</span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000ff;">$this</span>-&gt;_form = <span style="color: #000000; font-weight: bold;">new</span> Zend_Form<span style="color: #66cc66;">(</span><span style="color: #66cc66;">)</span>;</div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000ff;">$this</span>-&gt;_form-&gt;<span style="color: #006600;">setMethod</span><span style="color: #66cc66;">(</span><span style="color: #ff0000;">'get'</span><span style="color: #66cc66;">)</span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; -&gt;<span style="color: #006600;">setAction</span><span style="color: #66cc66;">(</span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000ff;">$this</span>-&gt;<span style="color: #006600;">getRequest</span><span style="color: #66cc66;">(</span><span style="color: #66cc66;">)</span>-&gt;<span style="color: #006600;">getBaseUrl</span><span style="color: #66cc66;">(</span><span style="color: #66cc66;">)</span> . <span style="color: #ff0000;">'/test/process'</span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">)</span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; -&gt;<span style="color: #006600;">addElements</span><span style="color: #66cc66;">(</span><a href="http://www.php.net/array"><span style="color: #000066;">array</span></a><span style="color: #66cc66;">(</span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #ff0000;">'test'</span> =&gt; <a href="http://www.php.net/array"><span style="color: #000066;">array</span></a><span style="color: #66cc66;">(</span><span style="color: #ff0000;">'type'</span> =&gt; <span style="color: #ff0000;">'text'</span>, <span style="color: #ff0000;">'options'</span> =&gt; <a href="http://www.php.net/array"><span style="color: #000066;">array</span></a><span style="color: #66cc66;">(</span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #ff0000;">'filters'</span>&nbsp; &nbsp; &nbsp; &nbsp; =&gt; <a href="http://www.php.net/array"><span style="color: #000066;">array</span></a><span style="color: #66cc66;">(</span><span style="color: #ff0000;">'StringTrim'</span><span style="color: #66cc66;">)</span>,</div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #ff0000;">'dojoType'</span>&nbsp; &nbsp; &nbsp; &nbsp;=&gt; <a href="http://www.php.net/array"><span style="color: #000066;">array</span></a><span style="color: #66cc66;">(</span><span style="color: #ff0000;">'dijit.form.ComboBox'</span><span style="color: #66cc66;">)</span>,</div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #ff0000;">'store'</span>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; =&gt; <span style="color: #ff0000;">'testStore'</span>,</div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #ff0000;">'autoComplete'</span>&nbsp; &nbsp;=&gt; <span style="color: #ff0000;">'false'</span>,</div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #ff0000;">'hasDownArrow'</span>&nbsp; &nbsp;=&gt; <span style="color: #ff0000;">'true'</span>,</div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #ff0000;">'label'</span> =&gt; <span style="color: #ff0000;">'Your input:'</span>,</div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">)</span><span style="color: #66cc66;">)</span>,</div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #ff0000;">'go'</span> =&gt; <a href="http://www.php.net/array"><span style="color: #000066;">array</span></a><span style="color: #66cc66;">(</span><span style="color: #ff0000;">'type'</span> =&gt; <span style="color: #ff0000;">'submit'</span>,</div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #ff0000;">'options'</span> =&gt; <a href="http://www.php.net/array"><span style="color: #000066;">array</span></a><span style="color: #66cc66;">(</span><span style="color: #ff0000;">'label'</span> =&gt; <span style="color: #ff0000;">'Go!'</span><span style="color: #66cc66;">)</span><span style="color: #66cc66;">)</span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">)</span><span style="color: #66cc66;">)</span>;</div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">}</span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">return</span> <span style="color: #0000ff;">$this</span>-&gt;_form;</div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #66cc66;">}</span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #66cc66;">}</span></div></li></ol></div></div></div>


            <div class="example-contents"><p>
                Here, we simply create a form with 'test' and 'go' methods. The
                'test' method adds several special, Dojo-specific attributes:
                dojoType, store, autoComplete, and hasDownArrow. The dojoType is
                used to indicate that we are creating a ComboBox, and we will
                link it to a data store (key 'store') of 'testStore' -- more on
                that later. Specifying 'autoComplete' as <b><tt>FALSE</tt></b> tells
                Dojo not to automatically select the first match, but instead show a list of
                matches. Finally, 'hasDownArrow' creates a down arrow similar to
                a select box so we can show and hide the matches.
            </p></div>

            <div class="example-contents"><p>
                Let's add a method to display the form, as well as an end point
                for processing AutoCompletion:
            </p></div>

            <div class="programlisting php"><div class="phpcode"><div class="php" style="font-family: monospace;"><ol><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #000000; font-weight: bold;">class</span> TestController <span style="color: #000000; font-weight: bold;">extends</span> Zend_Controller_Action</div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #66cc66;">{</span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #808080; font-style: italic;">// ...</span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #808080; font-style: italic;">/**</span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #808080; font-style: italic;">&nbsp; &nbsp; &nbsp;* Landing page</span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #808080; font-style: italic;">&nbsp; &nbsp; &nbsp;*/</span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> indexAction<span style="color: #66cc66;">(</span><span style="color: #66cc66;">)</span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #66cc66;">{</span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000ff;">$this</span>-&gt;<span style="color: #006600;">view</span>-&gt;<span style="color: #006600;">form</span> = <span style="color: #0000ff;">$this</span>-&gt;<span style="color: #006600;">getForm</span><span style="color: #66cc66;">(</span><span style="color: #66cc66;">)</span>;</div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #66cc66;">}</span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> autocompleteAction<span style="color: #66cc66;">(</span><span style="color: #66cc66;">)</span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #66cc66;">{</span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">if</span> <span style="color: #66cc66;">(</span><span style="color: #ff0000;">'ajax'</span> != <span style="color: #0000ff;">$this</span>-&gt;_getParam<span style="color: #66cc66;">(</span><span style="color: #ff0000;">'format'</span>, <span style="color: #000000; font-weight: bold;">false</span><span style="color: #66cc66;">)</span><span style="color: #66cc66;">)</span> <span style="color: #66cc66;">{</span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">return</span> <span style="color: #0000ff;">$this</span>-&gt;_helper-&gt;<span style="color: #006600;">redirector</span><span style="color: #66cc66;">(</span><span style="color: #ff0000;">'index'</span><span style="color: #66cc66;">)</span>;</div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">}</span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">if</span> <span style="color: #66cc66;">(</span><span style="color: #0000ff;">$this</span>-&gt;<span style="color: #006600;">getRequest</span><span style="color: #66cc66;">(</span><span style="color: #66cc66;">)</span>-&gt;<span style="color: #006600;">isPost</span><span style="color: #66cc66;">(</span><span style="color: #66cc66;">)</span><span style="color: #66cc66;">)</span> <span style="color: #66cc66;">{</span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">return</span> <span style="color: #0000ff;">$this</span>-&gt;_helper-&gt;<span style="color: #006600;">redirector</span><span style="color: #66cc66;">(</span><span style="color: #ff0000;">'index'</span><span style="color: #66cc66;">)</span>;</div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">}</span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000ff;">$match</span> = <a href="http://www.php.net/trim"><span style="color: #000066;">trim</span></a><span style="color: #66cc66;">(</span><span style="color: #0000ff;">$this</span>-&gt;<span style="color: #006600;">getRequest</span><span style="color: #66cc66;">(</span><span style="color: #66cc66;">)</span>-&gt;<span style="color: #006600;">getQuery</span><span style="color: #66cc66;">(</span><span style="color: #ff0000;">'test'</span>, <span style="color: #ff0000;">''</span><span style="color: #66cc66;">)</span><span style="color: #66cc66;">)</span>;</div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000ff;">$matches</span> = <a href="http://www.php.net/array"><span style="color: #000066;">array</span></a><span style="color: #66cc66;">(</span><span style="color: #66cc66;">)</span>;</div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">foreach</span> <span style="color: #66cc66;">(</span><span style="color: #0000ff;">$this</span>-&gt;<span style="color: #006600;">getData</span><span style="color: #66cc66;">(</span><span style="color: #66cc66;">)</span> <span style="color: #b1b100;">as</span> <span style="color: #0000ff;">$datum</span><span style="color: #66cc66;">)</span> <span style="color: #66cc66;">{</span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">if</span> <span style="color: #66cc66;">(</span><span style="color: #cc66cc;">0</span> === <a href="http://www.php.net/strpos"><span style="color: #000066;">strpos</span></a><span style="color: #66cc66;">(</span><span style="color: #0000ff;">$datum</span>, <span style="color: #0000ff;">$match</span><span style="color: #66cc66;">)</span><span style="color: #66cc66;">)</span> <span style="color: #66cc66;">{</span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000ff;">$matches</span><span style="color: #66cc66;">[</span><span style="color: #66cc66;">]</span> = <span style="color: #0000ff;">$datum</span>;</div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">}</span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">}</span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000ff;">$this</span>-&gt;_helper-&gt;<span style="color: #006600;">autoCompleteDojo</span><span style="color: #66cc66;">(</span><span style="color: #0000ff;">$matches</span><span style="color: #66cc66;">)</span>;</div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #66cc66;">}</span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #66cc66;">}</span></div></li></ol></div></div></div>


            <div class="example-contents"><p>
                In our  <span class="methodname">autocompleteAction()</span> we do a number of
                things. First, we look to make sure we have a post request, and
                that there is a 'format' parameter set to the value 'ajax';
                these are simply to help reduce spurious queries to the action.
                Next, we check for a 'test' parameter, and compare it against
                our data. (I purposely leave out the implementation of
                 <span class="methodname">getData()</span> here -- it could be any sort of data
                source.) Finally, we send our matches to our AutoCompletion
                helper.
            </p></div>

            <div class="example-contents"><p>
                Now that we have all the pieces on the backend, let's look at
                what we need to deliver in our view script for the landing page.
                First, we need to setup our data store, then render our form,
                and finally ensure that the appropriate Dojo libraries --
                including our custom data store -- get loaded. Let's look at the
                view script, which comments the steps:
            </p></div>

            <div class="programlisting php"><div class="phpcode"><div class="php" style="font-family: monospace;"><ol><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #808080; font-style: italic;">// setup our data store: ?&gt;</span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&lt;div dojoType=<span style="color: #ff0000;">"custom.TestNameReadStore"</span> jsId=<span style="color: #ff0000;">"testStore"</span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; url=<span style="color: #ff0000;">"&lt;?php echo $this-&gt;baseUrl() ?&gt;/unit-test/autocomplete/format/ajax"</span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; requestMethod=<span style="color: #ff0000;">"get"</span>&gt;&lt;/div&gt;</div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #808080; font-style: italic;">// render our form: ?&gt;</span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #000000; font-weight: bold;">&lt;?php</span> <a href="http://www.php.net/echo"><span style="color: #000066;">echo</span></a> <span style="color: #0000ff;">$this</span>-&gt;<span style="color: #006600;">form</span> <span style="color: #000000; font-weight: bold;">?&gt;</span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #808080; font-style: italic;">// setup Dojo-related CSS to load in HTML head: ?&gt;</span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #0000ff;">$this</span>-&gt;<span style="color: #006600;">headStyle</span><span style="color: #66cc66;">(</span><span style="color: #66cc66;">)</span>-&gt;<span style="color: #006600;">captureStart</span><span style="color: #66cc66;">(</span><span style="color: #66cc66;">)</span> <span style="color: #000000; font-weight: bold;">?&gt;</span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">@import <span style="color: #ff0000;">"&lt;?php echo $this-&gt;baseUrl()</span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #ff0000;">?&gt;/javascript/dijit/themes/tundra/tundra.css"</span>;</div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">@import <span style="color: #ff0000;">"&lt;?php echo $this-&gt;baseUrl() ?&gt;/javascript/dojo/resources/dojo.css"</span>;</div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #0000ff;">$this</span>-&gt;<span style="color: #006600;">headStyle</span><span style="color: #66cc66;">(</span><span style="color: #66cc66;">)</span>-&gt;<span style="color: #006600;">captureEnd</span><span style="color: #66cc66;">(</span><span style="color: #66cc66;">)</span> <span style="color: #000000; font-weight: bold;">?&gt;</span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #808080; font-style: italic;">// setup javascript to load in HTML head, including all required</span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp;<span style="color: #808080; font-style: italic;">// Dojo libraries: ?&gt;</span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #0000ff;">$this</span>-&gt;<span style="color: #006600;">headScript</span><span style="color: #66cc66;">(</span><span style="color: #66cc66;">)</span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; -&gt;<span style="color: #006600;">setAllowArbitraryAttributes</span><span style="color: #66cc66;">(</span><span style="color: #000000; font-weight: bold;">true</span><span style="color: #66cc66;">)</span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; -&gt;<span style="color: #006600;">appendFile</span><span style="color: #66cc66;">(</span><span style="color: #0000ff;">$this</span>-&gt;<span style="color: #006600;">baseUrl</span><span style="color: #66cc66;">(</span><span style="color: #66cc66;">)</span> . <span style="color: #ff0000;">'/javascript/dojo/dojo.js'</span>,</div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #ff0000;">'text/javascript'</span>,</div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <a href="http://www.php.net/array"><span style="color: #000066;">array</span></a><span style="color: #66cc66;">(</span><span style="color: #ff0000;">'djConfig'</span> =&gt; <span style="color: #ff0000;">'parseOnLoad: true'</span><span style="color: #66cc66;">)</span><span style="color: #66cc66;">)</span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; -&gt;<span style="color: #006600;">captureStart</span><span style="color: #66cc66;">(</span><span style="color: #66cc66;">)</span> <span style="color: #000000; font-weight: bold;">?&gt;</span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">djConfig.usePlainJson=<span style="color: #000000; font-weight: bold;">true</span>;</div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">dojo.registerModulePath<span style="color: #66cc66;">(</span><span style="color: #ff0000;">"custom"</span>,<span style="color: #ff0000;">"../custom"</span><span style="color: #66cc66;">)</span>;</div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">dojo.<span style="color: #b1b100;">require</span><span style="color: #66cc66;">(</span><span style="color: #ff0000;">"dojo.parser"</span><span style="color: #66cc66;">)</span>;</div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">dojo.<span style="color: #b1b100;">require</span><span style="color: #66cc66;">(</span><span style="color: #ff0000;">"dojox.data.QueryReadStore"</span><span style="color: #66cc66;">)</span>;</div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">dojo.<span style="color: #b1b100;">require</span><span style="color: #66cc66;">(</span><span style="color: #ff0000;">"dijit.form.ComboBox"</span><span style="color: #66cc66;">)</span>;</div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">dojo.<span style="color: #b1b100;">require</span><span style="color: #66cc66;">(</span><span style="color: #ff0000;">"custom.TestNameReadStore"</span><span style="color: #66cc66;">)</span>;</div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #0000ff;">$this</span>-&gt;<span style="color: #006600;">headScript</span><span style="color: #66cc66;">(</span><span style="color: #66cc66;">)</span>-&gt;<span style="color: #006600;">captureEnd</span><span style="color: #66cc66;">(</span><span style="color: #66cc66;">)</span> <span style="color: #000000; font-weight: bold;">?&gt;</span></div></li></ol></div></div></div>


            <div class="example-contents"><p>
                Note the calls to view helpers such as headStyle and headScript;
                these are placeholders, which we can then render in the <acronym class="acronym">HTML</acronym>
                head section of our layout view script.
            </p></div>

            <div class="example-contents"><p>
                We now have all the pieces to get Dojo AutoCompletion working.
            </p></div>
        </div>
    </div>

    <div class="section" id="zend.controller.actionhelpers.autocomplete.scriptaculous" name="zend.controller.actionhelpers.autocomplete.scriptaculous"><div class="info"><h4>AutoCompletion with Scriptaculous</h4></div>
        

        <p class="para">
            <a href="http://wiki.script.aculo.us/scriptaculous/show/Ajax.Autocompleter" class="link external">» Scriptaculous</a>
            expects an <acronym class="acronym">HTML</acronym> response in a specific format.
        </p>

        <p class="para">
            The helper to use with this library is 'AutoCompleteScriptaculous'.
            Simply provide it an array of data, and the helper will create an
            <acronym class="acronym">HTML</acronym> response compatible with Ajax.Autocompleter.
        </p>
    </div>
</div>
        <div class="section" id="zend.controller.actionhelpers.contextswitch" name="zend.controller.actionhelpers.contextswitch"><div class="info"><h3>ContextSwitch and AjaxContext</h3></div>
    

    <p class="para">
        The <em class="emphasis">ContextSwitch</em> action helper is intended for
        facilitating returning different response formats on request.
        The <em class="emphasis">AjaxContext</em> helper is a specialized version of
        <em class="emphasis">ContextSwitch</em> that facilitates returning responses
        to XmlHttpRequests.
    </p>

    <p class="para">
        To enable either one, you must provide hinting in your controller as to
        what actions can respond to which contexts. If an incoming request
        indicates a valid context for the given action, the helper will then:
    </p>

    <ul class="itemizedlist"><li class="listitem">
            <p class="para">
                Disable layouts, if enabled.
            </p>
        </li>

        <li class="listitem">
            <p class="para">
                Set an alternate view suffix, effectively requiring a separate
                view script for the context.
            </p>
        </li>

        <li class="listitem">
            <p class="para">
                Send appropriate response headers for the context desired.
            </p>
        </li>

        <li class="listitem">
            <p class="para">
                Optionally, call specified callbacks to setup the context and/or
                perform post-processing.
            </p>
        </li>
    </ul><p class="para">
        As an example, let's consider the following controller:
    </p>

    <div class="programlisting php"><div class="phpcode"><div class="php" style="font-family: monospace;"><ol><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #000000; font-weight: bold;">class</span> NewsController <span style="color: #000000; font-weight: bold;">extends</span> Zend_Controller_Action</div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #66cc66;">{</span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #808080; font-style: italic;">/**</span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #808080; font-style: italic;">&nbsp; &nbsp; &nbsp;* Landing page; forwards to listAction()</span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #808080; font-style: italic;">&nbsp; &nbsp; &nbsp;*/</span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> indexAction<span style="color: #66cc66;">(</span><span style="color: #66cc66;">)</span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #66cc66;">{</span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000ff;">$this</span>-&gt;_forward<span style="color: #66cc66;">(</span><span style="color: #ff0000;">'list'</span><span style="color: #66cc66;">)</span>;</div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #66cc66;">}</span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #808080; font-style: italic;">/**</span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #808080; font-style: italic;">&nbsp; &nbsp; &nbsp;* List news items</span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #808080; font-style: italic;">&nbsp; &nbsp; &nbsp;*/</span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> listAction<span style="color: #66cc66;">(</span><span style="color: #66cc66;">)</span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #66cc66;">{</span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #66cc66;">}</span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #808080; font-style: italic;">/**</span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #808080; font-style: italic;">&nbsp; &nbsp; &nbsp;* View a news item</span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #808080; font-style: italic;">&nbsp; &nbsp; &nbsp;*/</span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> viewAction<span style="color: #66cc66;">(</span><span style="color: #66cc66;">)</span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #66cc66;">{</span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #66cc66;">}</span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #66cc66;">}</span></div></li></ol></div></div></div>


    <p class="para">
        Let's say that we want the  <span class="methodname">listAction()</span> to also be
        available in an <acronym class="acronym">XML</acronym> format. Instead of creating a different action, we
        can hint that it can return an <acronym class="acronym">XML</acronym> response:
    </p>

    <div class="programlisting php"><div class="phpcode"><div class="php" style="font-family: monospace;"><ol><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #000000; font-weight: bold;">class</span> NewsController <span style="color: #000000; font-weight: bold;">extends</span> Zend_Controller_Action</div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #66cc66;">{</span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> init<span style="color: #66cc66;">(</span><span style="color: #66cc66;">)</span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #66cc66;">{</span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000ff;">$contextSwitch</span> = <span style="color: #0000ff;">$this</span>-&gt;_helper-&gt;<span style="color: #006600;">getHelper</span><span style="color: #66cc66;">(</span><span style="color: #ff0000;">'contextSwitch'</span><span style="color: #66cc66;">)</span>;</div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000ff;">$contextSwitch</span>-&gt;<span style="color: #006600;">addActionContext</span><span style="color: #66cc66;">(</span><span style="color: #ff0000;">'list'</span>, <span style="color: #ff0000;">'xml'</span><span style="color: #66cc66;">)</span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; -&gt;<span style="color: #006600;">initContext</span><span style="color: #66cc66;">(</span><span style="color: #66cc66;">)</span>;</div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #66cc66;">}</span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #808080; font-style: italic;">// ...</span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #66cc66;">}</span></div></li></ol></div></div></div>


    <p class="para">
        What this will do is:
    </p>

    <ul class="itemizedlist"><li class="listitem">
            <p class="para">
                Set the 'Content-Type' response header to '<var class="filename">application/xml</var>'.
            </p>
        </li>

        <li class="listitem">
            <p class="para">
                Change the view suffix to '<var class="filename">xml.phtml</var>' (or, if you use an
                alternate view suffix, 'xml.[your suffix]').
            </p>
        </li>
    </ul><p class="para">
        Now, you'll need to create a new view script, '<var class="filename">news/list.xml.phtml</var>',
        which will create and render the <acronym class="acronym">XML</acronym>.
    </p>

    <p class="para">
        To determine if a request should initiate a context switch, the helper
        checks for a token in the request object. By default, it looks for the
        'format' parameter, though this may be configured. This means that, in
        most cases, to trigger a context switch, you can add a 'format'
        parameter to your request:
    </p>

    <ul class="itemizedlist"><li class="listitem">
            <p class="para">
                Via <acronym class="acronym">URL</acronym> parameter: <var class="filename">/news/list/format/xml</var>
                (recall, the default routing schema allows for arbitrary key to value pairs
                following the action)
            </p>
        </li>

        <li class="listitem">
            <p class="para">
                Via <b><tt>GET</tt></b> parameter: <strong class="command">/news/list?format=xml</strong>
            </p>
        </li>
    </ul><p class="para">
        <em class="emphasis">ContextSwitch</em> allows you to specify arbitrary contexts,
        including what suffix change will occur (if any), any response headers
        that should be sent, and arbitrary callbacks for initialization and post
        processing.
    </p>

    <div class="section" id="zend.controller.actionhelpers.contextswitch.contexts" name="zend.controller.actionhelpers.contextswitch.contexts"><div class="info"><h4>Default Contexts Available</h4></div>
        

        <p class="para">
            By default, two contexts are available to the
            <em class="emphasis">ContextSwitch</em> helper: json and <acronym class="acronym">XML</acronym>.
        </p>

        <ul class="itemizedlist"><li class="listitem">
                <p class="para">
                    <em class="emphasis"><acronym class="acronym">JSON</acronym></em>. The <acronym class="acronym">JSON</acronym>
                    context sets the 'Content-Type' response header to
                    '<var class="filename">application/json</var>', and the view script suffix to
                    '<var class="filename">json.phtml</var>'.
                </p>

                <p class="para">
                    By default, however, no view script is required. It will
                    simply serialize all view variables, and emit the <acronym class="acronym">JSON</acronym>
                    response immediately.
                </p>

                <p class="para">
                    This behaviour can be disabled by turning off the automatic
                    <acronym class="acronym">JSON</acronym> serialization:
                </p>

                <div class="programlisting php"><div class="phpcode"><div class="php" style="font-family: monospace;"><ol><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #0000ff;">$this</span>-&gt;_helper-&gt;<span style="color: #006600;">contextSwitch</span><span style="color: #66cc66;">(</span><span style="color: #66cc66;">)</span>-&gt;<span style="color: #006600;">setAutoJsonSerialization</span><span style="color: #66cc66;">(</span><span style="color: #000000; font-weight: bold;">false</span><span style="color: #66cc66;">)</span>;</div></li></ol></div></div></div>

            </li>

            <li class="listitem">
                <p class="para">
                    <em class="emphasis"><acronym class="acronym">XML</acronym></em>. The <acronym class="acronym">XML</acronym> context
                    sets the 'Content-Type' response header to '<var class="filename">application/xml</var>', and
                    the view script suffix to '<var class="filename">xml.phtml</var>'. You will need to
                    create a new view script for the context.
                </p>
            </li>
        </ul></div>

    <div class="section" id="zend.controller.actionhelpers.contextswitch.custom" name="zend.controller.actionhelpers.contextswitch.custom"><div class="info"><h4>Creating Custom Contexts</h4></div>
        

        <p class="para">
            Sometimes, the default contexts are not enough. For instance, you may wish to return
            <acronym class="acronym">YAML</acronym>, or serialized <acronym class="acronym">PHP</acronym>, an
            <acronym class="acronym">RSS</acronym> or <acronym class="acronym">ATOM</acronym> feed, etc.
            <em class="emphasis">ContextSwitch</em> allows you to do so.
        </p>

        <p class="para">
            The easiest way to add a new context is via the
             <span class="methodname">addContext()</span> method. This method takes two arguments,
            the name of the context, and an array specification. The
            specification should include one or more of the following:
        </p>

        <ul class="itemizedlist"><li class="listitem">
                <p class="para">
                    <em class="emphasis">suffix</em>: the suffix to prepend to the
                    default view suffix as registered in the ViewRenderer.
                </p>
            </li>

            <li class="listitem">
                <p class="para">
                    <em class="emphasis">headers</em>: an array of header to value
                    pairs you wish sent as part of the response.
                </p>
            </li>

            <li class="listitem">
                <p class="para">
                    <em class="emphasis">callbacks</em>: an array containing one or
                    more of the keys 'init' or 'post', pointing to valid <acronym class="acronym">PHP</acronym>
                    callbacks that can be used for context initialization and post
                    processing.
                </p>

                <p class="para">
                    Initialization callbacks occur when the context is
                    detected by <em class="emphasis">ContextSwitch</em>. You can use it to
                    perform arbitrary logic that should occur. As an example,
                    the <acronym class="acronym">JSON</acronym> context uses a callback to disable the ViewRenderer
                    when the automatic <acronym class="acronym">JSON</acronym> serialization is on.
                </p>

                <p class="para">
                    Post processing occurs during the action's
                     <span class="methodname">postDispatch()</span> routine, and can be used to perform
                    arbitrary logic. As an example, the <acronym class="acronym">JSON</acronym> context uses a
                    callback to determine if the automatic <acronym class="acronym">JSON</acronym> serialization is
                    on; if so, it serializes the view variables to <acronym class="acronym">JSON</acronym> and sends
                    the response, but if not, it re-enables the ViewRenderer.
                </p>
            </li>
        </ul><p class="para">
            There are a variety of methods for interacting with contexts:
        </p>

        <ul class="itemizedlist"><li class="listitem">
                <p class="para">
                     <span class="methodname">addContext($context, array $spec)</span>: add a new
                    context. Throws an exception if the context already exists.
                </p>
            </li>

            <li class="listitem">
                <p class="para">
                     <span class="methodname">setContext($context, array $spec)</span>: add a new
                    context or overwrite an existing context. Uses the same
                    specification as  <span class="methodname">addContext()</span>.
                </p>
            </li>

            <li class="listitem">
                <p class="para">
                     <span class="methodname">addContexts(array $contexts)</span>: add many contexts at
                    once. The <var class="varname">$contexts</var> array should be an array of
                    context to specification pairs. If any of the contexts already
                    exists, it will throw an exception.
                </p>
            </li>

            <li class="listitem">
                <p class="para">
                     <span class="methodname">setContexts(array $contexts)</span>: add new contexts and
                overwrite existing ones. Uses the same specification as
                 <span class="methodname">addContexts()</span>.
            </p>
            </li>

            <li class="listitem">
            <p class="para">
                 <span class="methodname">hasContext($context)</span>: returns <b><tt>TRUE</tt></b> if
                the context exists, <b><tt>FALSE</tt></b> otherwise.
            </p>
            </li>

            <li class="listitem">
                <p class="para">
                     <span class="methodname">getContext($context)</span>: retrieve a
                    single context by name. Returns an array following the
                    specification used in  <span class="methodname">addContext()</span>.
                </p>
            </li>

            <li class="listitem">
                <p class="para">
                     <span class="methodname">getContexts()</span>: retrieve all contexts. Returns an
                    array of context to specification pairs.
                </p>
            </li>

            <li class="listitem">
                <p class="para">
                     <span class="methodname">removeContext($context)</span>: remove a single context by
                    name. Returns <b><tt>TRUE</tt></b> if successful,
                    <b><tt>FALSE</tt></b> if the context was not found.
                </p>
            </li>

            <li class="listitem">
                <p class="para">
                     <span class="methodname">clearContexts()</span>: remove all contexts.
                </p>
            </li>
        </ul></div>

    <div class="section" id="zend.controller.actionhelpers.contextswitch.actions" name="zend.controller.actionhelpers.contextswitch.actions"><div class="info"><h4>Setting Contexts Per Action</h4></div>
        

        <p class="para">
            There are two mechanisms for setting available contexts. You can
            either manually create arrays in your controller, or use several
            methods in <em class="emphasis">ContextSwitch</em> to assemble them.
        </p>

        <p class="para">
            The principle method for adding action to context relations is
             <span class="methodname">addActionContext()</span>. It expects two arguments, the
            action to which the context is being added, and either the name of a
            context or an array of contexts. As an example, consider the
            following controller class:
        </p>

        <div class="programlisting php"><div class="phpcode"><div class="php" style="font-family: monospace;"><ol><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #000000; font-weight: bold;">class</span> FooController <span style="color: #000000; font-weight: bold;">extends</span> Zend_Controller_Action</div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #66cc66;">{</span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> listAction<span style="color: #66cc66;">(</span><span style="color: #66cc66;">)</span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #66cc66;">{</span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #66cc66;">}</span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> viewAction<span style="color: #66cc66;">(</span><span style="color: #66cc66;">)</span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #66cc66;">{</span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #66cc66;">}</span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> commentsAction<span style="color: #66cc66;">(</span><span style="color: #66cc66;">)</span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #66cc66;">{</span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #66cc66;">}</span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> updateAction<span style="color: #66cc66;">(</span><span style="color: #66cc66;">)</span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #66cc66;">{</span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #66cc66;">}</span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #66cc66;">}</span></div></li></ol></div></div></div>


        <p class="para">
            Let's say we wanted to add an <acronym class="acronym">XML</acronym> context to the 'list' action, and
            <acronym class="acronym">XML</acronym> and <acronym class="acronym">JSON</acronym> contexts to the 'comments' action.
            We could do so in the  <span class="methodname">init()</span> method:
        </p>

        <div class="programlisting php"><div class="phpcode"><div class="php" style="font-family: monospace;"><ol><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #000000; font-weight: bold;">class</span> FooController <span style="color: #000000; font-weight: bold;">extends</span> Zend_Controller_Action</div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #66cc66;">{</span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> init<span style="color: #66cc66;">(</span><span style="color: #66cc66;">)</span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #66cc66;">{</span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000ff;">$this</span>-&gt;_helper-&gt;<span style="color: #006600;">contextSwitch</span><span style="color: #66cc66;">(</span><span style="color: #66cc66;">)</span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;-&gt;<span style="color: #006600;">addActionContext</span><span style="color: #66cc66;">(</span><span style="color: #ff0000;">'list'</span>, <span style="color: #ff0000;">'xml'</span><span style="color: #66cc66;">)</span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;-&gt;<span style="color: #006600;">addActionContext</span><span style="color: #66cc66;">(</span><span style="color: #ff0000;">'comments'</span>, <a href="http://www.php.net/array"><span style="color: #000066;">array</span></a><span style="color: #66cc66;">(</span><span style="color: #ff0000;">'xml'</span>, <span style="color: #ff0000;">'json'</span><span style="color: #66cc66;">)</span><span style="color: #66cc66;">)</span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;-&gt;<span style="color: #006600;">initContext</span><span style="color: #66cc66;">(</span><span style="color: #66cc66;">)</span>;</div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #66cc66;">}</span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #66cc66;">}</span></div></li></ol></div></div></div>


        <p class="para">
            Alternately, you could simply define the array property
            <var class="varname">$contexts</var>:
        </p>

        <div class="programlisting php"><div class="phpcode"><div class="php" style="font-family: monospace;"><ol><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #000000; font-weight: bold;">class</span> FooController <span style="color: #000000; font-weight: bold;">extends</span> Zend_Controller_Action</div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #66cc66;">{</span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #0000ff;">$contexts</span> = <a href="http://www.php.net/array"><span style="color: #000066;">array</span></a><span style="color: #66cc66;">(</span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #ff0000;">'list'</span>&nbsp; &nbsp; &nbsp;=&gt; <a href="http://www.php.net/array"><span style="color: #000066;">array</span></a><span style="color: #66cc66;">(</span><span style="color: #ff0000;">'xml'</span><span style="color: #66cc66;">)</span>,</div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #ff0000;">'comments'</span> =&gt; <a href="http://www.php.net/array"><span style="color: #000066;">array</span></a><span style="color: #66cc66;">(</span><span style="color: #ff0000;">'xml'</span>, <span style="color: #ff0000;">'json'</span><span style="color: #66cc66;">)</span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #66cc66;">)</span>;</div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> init<span style="color: #66cc66;">(</span><span style="color: #66cc66;">)</span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #66cc66;">{</span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000ff;">$this</span>-&gt;_helper-&gt;<span style="color: #006600;">contextSwitch</span><span style="color: #66cc66;">(</span><span style="color: #66cc66;">)</span>-&gt;<span style="color: #006600;">initContext</span><span style="color: #66cc66;">(</span><span style="color: #66cc66;">)</span>;</div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #66cc66;">}</span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #66cc66;">}</span></div></li></ol></div></div></div>


        <p class="para">
            The above is less overhead, but also prone to potential errors.
        </p>

        <p class="para">
            The following methods can be used to build the context mappings:
        </p>

        <ul class="itemizedlist"><li class="listitem">
                <p class="para">
                     <span class="methodname">addActionContext($action, $context)</span>: marks one
                    or more contexts as available to an action. If mappings
                    already exists, simply appends to those mappings.
                    <var class="varname">$context</var> may be a single context, or an array
                    of contexts.
                </p>

                <p class="para">
                    A value of <b><tt>TRUE</tt></b> for the context will mark
                    all available contexts as available for the action.
                </p>

                <p class="para">
                    An empty value for <var class="varname">$context</var> will disable all contexts for
                    the given action.
                </p>
            </li>

            <li class="listitem">
                <p class="para">
                     <span class="methodname">setActionContext($action, $context)</span>: marks one
                    or more contexts as available to an action. If mappings
                    already exists, it replaces them with those specified.
                    <var class="varname">$context</var> may be a single context, or an array
                    of contexts.
                </p>
            </li>

            <li class="listitem">
                <p class="para">
                     <span class="methodname">addActionContexts(array $contexts)</span>: add several
                    action to context pairings at once. <var class="varname">$contexts</var>
                    should be an associative array of action to context pairs. It
                    proxies to  <span class="methodname">addActionContext()</span>, meaning that if
                    pairings already exist, it appends to them.
                </p>
            </li>

            <li class="listitem">
                <p class="para">
                     <span class="methodname">setActionContexts(array $contexts)</span>: acts like
                     <span class="methodname">addActionContexts()</span>, but overwrites existing
                    action to context pairs.
                </p>
            </li>

            <li class="listitem">
                <p class="para">
                     <span class="methodname">hasActionContext($action, $context)</span>: determine
                    if a particular action has a given context.
                </p>
            </li>

            <li class="listitem">
                <p class="para">
                     <span class="methodname">getActionContexts($action = null)</span>: returns
                    either all contexts for a given action, or all
                    action to context pairs.
                </p>
            </li>

            <li class="listitem">
                <p class="para">
                     <span class="methodname">removeActionContext($action, $context)</span>: remove
                    one or more contexts from a given action.
                    <var class="varname">$context</var> may be a single context or an array of
                    contexts.
                </p>
            </li>

            <li class="listitem">
                <p class="para">
                     <span class="methodname">clearActionContexts($action = null)</span>: remove all
                    contexts from a given action, or from all actions with
                    contexts.
                </p>
            </li>
        </ul></div>

    <div class="section" id="zend.controller.actionhelpers.contextswitch.initcontext" name="zend.controller.actionhelpers.contextswitch.initcontext"><div class="info"><h4>Initializing Context Switching</h4></div>
        

        <p class="para">
            To initialize context switching, you need to call
             <span class="methodname">initContext()</span> in your action controller:
        </p>

        <div class="programlisting php"><div class="phpcode"><div class="php" style="font-family: monospace;"><ol><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #000000; font-weight: bold;">class</span> NewsController <span style="color: #000000; font-weight: bold;">extends</span> Zend_Controller_Action</div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #66cc66;">{</span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> init<span style="color: #66cc66;">(</span><span style="color: #66cc66;">)</span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #66cc66;">{</span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000ff;">$this</span>-&gt;_helper-&gt;<span style="color: #006600;">contextSwitch</span><span style="color: #66cc66;">(</span><span style="color: #66cc66;">)</span>-&gt;<span style="color: #006600;">initContext</span><span style="color: #66cc66;">(</span><span style="color: #66cc66;">)</span>;</div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #66cc66;">}</span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #66cc66;">}</span></div></li></ol></div></div></div>


        <p class="para">
            In some cases, you may want to force the context used; for instance,
            you may only want to allow the <acronym class="acronym">XML</acronym> context if context switching is
            activated. You can do so by passing the context to
             <span class="methodname">initContext()</span>:
        </p>

        <div class="programlisting php"><div class="phpcode"><div class="php" style="font-family: monospace;"><ol><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #0000ff;">$contextSwitch</span>-&gt;<span style="color: #006600;">initContext</span><span style="color: #66cc66;">(</span><span style="color: #ff0000;">'xml'</span><span style="color: #66cc66;">)</span>;</div></li></ol></div></div></div>

    </div>

    <div class="section" id="zend.controller.actionhelpers.contextswitch.misc" name="zend.controller.actionhelpers.contextswitch.misc"><div class="info"><h4>Additional Functionality</h4></div>
        

        <p class="para">
            A variety of methods can be used to alter the behaviour of the
            <em class="emphasis">ContextSwitch</em> helper. These include:
        </p>

        <ul class="itemizedlist"><li class="listitem">
                <p class="para">
                     <span class="methodname">setAutoJsonSerialization($flag)</span>: By default,
                    <acronym class="acronym">JSON</acronym> contexts will serialize any view variables to
                    <acronym class="acronym">JSON</acronym> notation and return this as a response. If you wish to
                    create your own response, you should turn this off; this
                    needs to be done prior to the call to
                     <span class="methodname">initContext()</span>.
                </p>

                <div class="programlisting php"><div class="phpcode"><div class="php" style="font-family: monospace;"><ol><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #0000ff;">$contextSwitch</span>-&gt;<span style="color: #006600;">setAutoJsonSerialization</span><span style="color: #66cc66;">(</span><span style="color: #000000; font-weight: bold;">false</span><span style="color: #66cc66;">)</span>;</div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #0000ff;">$contextSwitch</span>-&gt;<span style="color: #006600;">initContext</span><span style="color: #66cc66;">(</span><span style="color: #66cc66;">)</span>;</div></li></ol></div></div></div>


                <p class="para">
                    You can retrieve the value of the flag with
                     <span class="methodname">getAutoJsonSerialization()</span>.
                </p>
            </li>

            <li class="listitem">
                <p class="para">
                     <span class="methodname">setSuffix($context, $suffix,
                        $prependViewRendererSuffix)</span>: With this method,
                    you can specify a different suffix to use for a given
                    context. The third argument is used to indicate whether or
                    not to prepend the current ViewRenderer suffix with the new
                    suffix; this flag is enabled by default.
                </p>

                <p class="para">
                    Passing an empty value to the suffix will cause only the
                    ViewRenderer suffix to be used.
                </p>
            </li>

            <li class="listitem">
                <p class="para">
                     <span class="methodname">addHeader($context, $header, $content)</span>: Add a
                    response header for a given context. <var class="varname">$header</var> is
                    the header name, and <var class="varname">$content</var> is the value to
                    pass for that header.
                </p>

                <p class="para">
                    Each context can have multiple headers;
                     <span class="methodname">addHeader()</span> adds additional headers to the
                    context's header stack.
                </p>

                <p class="para">
                    If the <var class="varname">$header</var> specified already exists for the
                    context, an exception will be thrown.
                </p>
            </li>

            <li class="listitem">
                <p class="para">
                     <span class="methodname">setHeader($context, $header, $content)</span>:
                     <span class="methodname">setHeader()</span> acts just like
                     <span class="methodname">addHeader()</span>, except it allows you to overwrite
                    existing context headers.
                </p>
            </li>

            <li class="listitem">
                <p class="para">
                     <span class="methodname">addHeaders($context, array $headers)</span>: Add
                    multiple headers at once to a given context. Proxies to
                     <span class="methodname">addHeader()</span>, so if the header already exists,
                    an exception will be thrown. <var class="varname">$headers</var> is an
                    array of header to context pairs.
                </p>
            </li>

            <li class="listitem">
                <p class="para">
                     <span class="methodname">setHeaders($context, array $headers.)</span>: like
                     <span class="methodname">addHeaders()</span>, except it proxies to
                     <span class="methodname">setHeader()</span>, allowing you to overwrite existing
                    headers.
                </p>
            </li>

            <li class="listitem">
                <p class="para">
                     <span class="methodname">getHeader($context, $header)</span>: retrieve the
                    value of a header for a given context. Returns <b><tt>NULL</tt></b> if not
                    found.
                </p>
            </li>

            <li class="listitem">
                <p class="para">
                     <span class="methodname">removeHeader($context, $header)</span>: remove a
                    single header for a given context.
                </p>
            </li>

            <li class="listitem">
                <p class="para">
                     <span class="methodname">clearHeaders($context, $header)</span>: remove all
                    headers for a given context.
                </p>
            </li>

            <li class="listitem">
                <p class="para">
                     <span class="methodname">setCallback($context, $trigger, $callback)</span>: set
                    a callback at a given trigger for a given context. Triggers
                    may be either 'init' or 'post' (indicating callback will be
                    called at either context initialization or postDispatch).
                    <var class="varname">$callback</var> should be a valid <acronym class="acronym">PHP</acronym> callback.
                </p>
            </li>

            <li class="listitem">
                <p class="para">
                     <span class="methodname">setCallbacks($context, array $callbacks)</span>: set
                    multiple callbacks for a given context. <var class="varname">$callbacks</var>
                    should be trigger to callback pairs. In actuality, the most callbacks
                    that can be registered are two, one for initialization and
                    one for post processing.
                </p>
            </li>

            <li class="listitem">
                <p class="para">
                     <span class="methodname">getCallback($context, $trigger)</span>: retrieve a
                    callback for a given trigger in a given context.
                </p>
            </li>

            <li class="listitem">
                <p class="para">
                     <span class="methodname">getCallbacks($context)</span>: retrieve all callbacks
                    for a given context. Returns an array of trigger to callback
                    pairs.
                </p>
            </li>

            <li class="listitem">
                <p class="para">
                     <span class="methodname">removeCallback($context, $trigger)</span>: remove a
                    callback for a given trigger and context.
                </p>
            </li>

            <li class="listitem">
                <p class="para">
                     <span class="methodname">clearCallbacks($context)</span>: remove all
                    callbacks for a given context.
                </p>
            </li>

            <li class="listitem">
                <p class="para">
                     <span class="methodname">setContextParam($name)</span>: set the request
                    parameter to check when determining if a context switch has
                    been requested. The value defaults to 'format', but this
                    accessor can be used to set an alternate value.
                </p>

                <p class="para">
                     <span class="methodname">getContextParam()</span> can be used to retrieve the
                    current value.
                </p>
            </li>

            <li class="listitem">
                <p class="para">
                     <span class="methodname">setAutoDisableLayout($flag)</span>: By default,
                    layouts are disabled when a context switch occurs; this is
                    because typically layouts will only be used for returning
                    normal responses, and have no meaning in alternate contexts.
                    However, if you wish to use layouts (perhaps you may have a
                    layout for the new context), you can change this behaviour
                    by passing a <b><tt>FALSE</tt></b> value to
                     <span class="methodname">setAutoDisableLayout()</span>. You should do this
                    <em class="emphasis">before</em> calling
                     <span class="methodname">initContext()</span>.
                </p>

                <p class="para">
                    To get the value of this flag, use the accessor
                     <span class="methodname">getAutoDisableLayout()</span>.
                </p>
            </li>

            <li class="listitem">
                <p class="para">
                     <span class="methodname">getCurrentContext()</span> can be used to determine
                    what context was detected, if any. This returns <b><tt>NULL</tt></b> if no
                    context switch occurred, or if called before
                     <span class="methodname">initContext()</span> has been invoked.
                </p>
            </li>
        </ul></div>

    <div class="section" id="zend.controller.actionhelpers.contextswitch.ajaxcontext" name="zend.controller.actionhelpers.contextswitch.ajaxcontext"><div class="info"><h4>AjaxContext Functionality</h4></div>
        

        <p class="para">
            The <em class="emphasis">AjaxContext</em> helper extends
            <em class="emphasis">ContextSwitch</em>, so all of the functionality listed for
            <em class="emphasis">ContextSwitch</em> is available to it. There are a few key
            differences, however.
        </p>

        <p class="para">
            First, it uses a different action controller property for
            determining contexts, <var class="varname">$ajaxable</var>. This is so you can
            have different contexts used for <acronym class="acronym">AJAX</acronym> versus normal
            <acronym class="acronym">HTTP</acronym> requests. The various
            * <span class="methodname">ActionContext()</span>* methods of
            <em class="emphasis">AjaxContext</em> will write to this property.
        </p>

        <p class="para">
            Second, it will only trigger if an XmlHttpRequest has occurred, as
            determined by the request object's  <span class="methodname">isXmlHttpRequest()</span>
            method. Thus, if the context parameter ('format') is passed in the
            request, but the request was not made as an XmlHttpRequest, no
            context switch will trigger.
        </p>

        <p class="para">
            Third, <em class="emphasis">AjaxContext</em> adds an additional context,
            <acronym class="acronym">HTML</acronym>. In this context, it sets the suffix to
            '<var class="filename">ajax.phtml</var>' in order to differentiate the context from a normal
            request. No additional headers are returned.
        </p>

        <div class="example"><div class="info"><p><b>Example #4 Allowing Actions to Respond To Ajax Requests</b></p></div>
            

            <div class="example-contents"><p>
                In this following example, we're allowing requests to the
                actions 'view', 'form', and 'process' to respond to <acronym class="acronym">AJAX</acronym>
                requests. In the first two cases, 'view' and 'form', we'll
                return <acronym class="acronym">HTML</acronym> snippets with which to update the page; in the
                latter, we'll return <acronym class="acronym">JSON</acronym>.
            </p></div>

            <div class="programlisting php"><div class="phpcode"><div class="php" style="font-family: monospace;"><ol><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #000000; font-weight: bold;">class</span> CommentController <span style="color: #000000; font-weight: bold;">extends</span> Zend_Controller_Action</div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #66cc66;">{</span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> init<span style="color: #66cc66;">(</span><span style="color: #66cc66;">)</span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #66cc66;">{</span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000ff;">$ajaxContext</span> = <span style="color: #0000ff;">$this</span>-&gt;_helper-&gt;<span style="color: #006600;">getHelper</span><span style="color: #66cc66;">(</span><span style="color: #ff0000;">'AjaxContext'</span><span style="color: #66cc66;">)</span>;</div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000ff;">$ajaxContext</span>-&gt;<span style="color: #006600;">addActionContext</span><span style="color: #66cc66;">(</span><span style="color: #ff0000;">'view'</span>, <span style="color: #ff0000;">'html'</span><span style="color: #66cc66;">)</span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; -&gt;<span style="color: #006600;">addActionContext</span><span style="color: #66cc66;">(</span><span style="color: #ff0000;">'form'</span>, <span style="color: #ff0000;">'html'</span><span style="color: #66cc66;">)</span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; -&gt;<span style="color: #006600;">addActionContext</span><span style="color: #66cc66;">(</span><span style="color: #ff0000;">'process'</span>, <span style="color: #ff0000;">'json'</span><span style="color: #66cc66;">)</span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; -&gt;<span style="color: #006600;">initContext</span><span style="color: #66cc66;">(</span><span style="color: #66cc66;">)</span>;</div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #66cc66;">}</span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> viewAction<span style="color: #66cc66;">(</span><span style="color: #66cc66;">)</span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #66cc66;">{</span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080; font-style: italic;">// Pull a single comment to view.</span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080; font-style: italic;">// When AjaxContext detected, uses the comment/view.ajax.phtml</span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080; font-style: italic;">// view script.</span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #66cc66;">}</span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> formAction<span style="color: #66cc66;">(</span><span style="color: #66cc66;">)</span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #66cc66;">{</span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080; font-style: italic;">// Render the "add new comment" form.</span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080; font-style: italic;">// When AjaxContext detected, uses the comment/form.ajax.phtml</span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080; font-style: italic;">// view script.</span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #66cc66;">}</span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> processAction<span style="color: #66cc66;">(</span><span style="color: #66cc66;">)</span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #66cc66;">{</span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080; font-style: italic;">// Process a new comment</span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080; font-style: italic;">// Return the results as JSON; simply assign the results as</span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080; font-style: italic;">// view variables, and JSON will be returned.</span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #66cc66;">}</span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #66cc66;">}</span></div></li></ol></div></div></div>


            <div class="example-contents"><p>
                On the client end, your <acronym class="acronym">AJAX</acronym> library will simply request the
                endpoints '<var class="filename">/comment/view</var>',
                '<var class="filename">/comment/form</var>', and
                '<var class="filename">/comment/process</var>', and pass the 'format' parameter:
                '<var class="filename">/comment/view/format/html</var>',
                '<var class="filename">/comment/form/format/html</var>',
                '<var class="filename">/comment/process/format/json</var>'. (Or you can pass the parameter
                via query string: e.g., "?format=json".)
            </p></div>

            <div class="example-contents"><p>
                Assuming your library passes the 'X-Requested-With:
                XmlHttpRequest' header, these actions will then return the
                appropriate response format.
            </p></div>
        </div>
    </div>
</div>
        <div class="section" id="zend.controller.actionhelpers.flashmessenger" name="zend.controller.actionhelpers.flashmessenger"><div class="info"><h3>FlashMessenger</h3></div>
    

    <div class="section" id="zend.controller.actionhelper.flashmessenger.introduction" name="zend.controller.actionhelper.flashmessenger.introduction"><div class="info"><h4>Introduction</h4></div>
        

        <p class="para">
            The <em class="emphasis">FlashMessenger</em> helper allows you to pass messages
            that the user may need to see on the next request. To accomplish
            this, <em class="emphasis">FlashMessenger</em> uses
            <span class="classname">Zend_Session_Namespace</span> to store messages for future or
            next request retrieval. It is generally a good idea that if you
            plan on using <span class="classname">Zend_Session</span> or
            <span class="classname">Zend_Session_Namespace</span>, that you initialize with
             <span class="methodname">Zend_Session::start()</span> in your bootstrap file. (See the
            <a href="http://framework.zend.com/manual/1.12/en/zend.session.advanced_usage.html#zend.session.advanced_usage.starting_a_session" class="link">Zend_Session</a>
            documentation for more details on its usage.)
        </p>
    </div>

    <div class="section" id="zend.controller.actionhelper.flashmessenger.api" name="zend.controller.actionhelper.flashmessenger.api"><div class="info"><h4>Available Methods</h4></div>
        

        <p class="para">
            General methods:
        </p>

        <ul class="itemizedlist"><li class="listitem">
                <p class="para">
                     <span class="methodname">setNamespace($namespace='default')</span> is used to set the namespace
                     into which messages are stored by default. 
                </p>
            </li>
            <li class="listitem">
                <p class="para">
                     <span class="methodname">getNamespace()</span> is used to retrieve the name of the 
                    default namespace.  The default namespace is 'default'.
                </p>
            </li>
            <li class="listitem">
                <p class="para">
                     <span class="methodname">resetNamespace()</span> is used to reset the namespace name
                    to the default value, 'default'.
                </p>
            </li>
        </ul><p class="para">
            Methods for manipulating messages set in the previous request:
        </p>

        <ul class="itemizedlist"><li class="listitem">
                <p class="para">
                     <span class="methodname">hasMessages($namespace=NULL)</span> is used to determine
                    if messages have been carried from a previous request by the flash messenger.  The
                    optional argument <var class="varname">$namespace</var> specifies which namespace to look in.
                    If the <var class="varname">$namespace</var> argument is omitted, the value returned by
                     <span class="methodname">getNamespace()</span> will be used.
                </p>
            </li>
            <li class="listitem">
                <p class="para">
                     <span class="methodname">getMessages($namespace=NULL)</span> is used to retrieve the
                    messages which have been carried from a previous request by the flash messenger.  The
                    optional argument <var class="varname">$namespace</var> specifies which namespace to pull from.
                    If the <var class="varname">$namespace</var> argument is omitted, the value returned by
                     <span class="methodname">getNamespace()</span> will be used.
                </p>
            </li>
            <li class="listitem">
                <p class="para">
                     <span class="methodname">getIterator($namespace=NULL)</span> wraps the return value of 
                     <span class="methodname">getMessages()</span> in an instance of <span class="classname">ArrayObject</span>.
                    If the <var class="varname">$namespace</var> argument is omitted, the value returned by
                     <span class="methodname">getNamespace()</span> will be used.
                </p>
            </li>
            <li class="listitem">
                <p class="para">
                     <span class="methodname">count($namespace=NULL)</span> returns the number of messages contained
                    in the specified namespace.  If the <var class="varname">$namespace</var> argument is omitted, the 
                    value returned by  <span class="methodname">getNamespace()</span> will be used.
                </p>
            </li>
            <li class="listitem">
                <p class="para">
                     <span class="methodname">clearMessages($namespace=NULL)</span> is used to clear all the
                    messages which have been carried from a previous request by the flash messenger.  The
                    optional argument <var class="varname">$namespace</var> specifies which namespace to clear out.
                    If the <var class="varname">$namespace</var> argument is omitted, the value returned by
                     <span class="methodname">getNamespace()</span> will be used.
                </p>
            </li>
        </ul><p class="para">
            Methods for manipulating messages set in the current request:
        </p>

        <ul class="itemizedlist"><li class="listitem">
                <p class="para">
                     <span class="methodname">addMessage($message, $namespace=NULL)</span> is used to add a new 
                    message to the current request.  <var class="varname">$message</var> contains the message
                    to be added, and the optional argument <var class="varname">$namespace</var> will specify
                    the namespace.  If the <var class="varname">$namespace</var> argument is omitted, the value
                    returned by  <span class="methodname">getNamespace()</span> will be used.
                </p>
            </li>
            <li class="listitem">
                <p class="para">
                     <span class="methodname">hasCurrentMessages($namespace=NULL)</span> is used to determine
                    if messages have been added to the flash messenger during the current request.  The
                    optional argument <var class="varname">$namespace</var> specifies which namespace to look in.
                    If the <var class="varname">$namespace</var> argument is omitted, the value returned by
                     <span class="methodname">getNamespace()</span> will be used.
                </p>
            </li>
            <li class="listitem">
                <p class="para">
                     <span class="methodname">getCurrentMessages($namespace=NULL)</span> is used to retrieve the
                    messages which have been added to the flash messenger during the current request.  The
                    optional argument <var class="varname">$namespace</var> specifies which namespace to pull from.
                    If the <var class="varname">$namespace</var> argument is omitted, the value returned by
                     <span class="methodname">getNamespace()</span> will be used.
                </p>
            </li>
            <li class="listitem">
                <p class="para">
                     <span class="methodname">clearCurrentMessages($namespace=NULL)</span> is used to clear all the
                    messages which have been added to the flash messenger during the current request.  The
                    optional argument <var class="varname">$namespace</var> specifies which namespace to clear out.
                    If the <var class="varname">$namespace</var> argument is omitted, the value returned by
                     <span class="methodname">getNamespace()</span> will be used.
                </p>
            </li>
        </ul></div>

    <div class="section" id="zend.controller.actionhelper.flashmessenger.basicusage" name="zend.controller.actionhelper.flashmessenger.basicusage"><div class="info"><h4>Basic Usage Example</h4></div>
        

        <p class="para">
            The usage example below shows the use of the flash messenger at its
            most basic. When the action <var class="filename">/some/my</var> is called, it adds
            the flash message "Record Saved!" A subsequent request to the action
            <var class="filename">/some/my-next-request</var> will retrieve it (and thus delete
            it as well).
        </p>

        <div class="programlisting php"><div class="phpcode"><div class="php" style="font-family: monospace;"><ol><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #000000; font-weight: bold;">class</span> SomeController <span style="color: #000000; font-weight: bold;">extends</span> Zend_Controller_Action</div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #66cc66;">{</span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #808080; font-style: italic;">/**</span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #808080; font-style: italic;">&nbsp; &nbsp; &nbsp;* FlashMessenger</span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #808080; font-style: italic;">&nbsp; &nbsp; &nbsp;*</span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #808080; font-style: italic;">&nbsp; &nbsp; &nbsp;* @var Zend_Controller_Action_Helper_FlashMessenger</span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #808080; font-style: italic;">&nbsp; &nbsp; &nbsp;*/</span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; protected <span style="color: #0000ff;">$_flashMessenger</span> = <span style="color: #000000; font-weight: bold;">null</span>;</div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> init<span style="color: #66cc66;">(</span><span style="color: #66cc66;">)</span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #66cc66;">{</span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000ff;">$this</span>-&gt;_flashMessenger =</div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000ff;">$this</span>-&gt;_helper-&gt;<span style="color: #006600;">getHelper</span><span style="color: #66cc66;">(</span><span style="color: #ff0000;">'FlashMessenger'</span><span style="color: #66cc66;">)</span>;</div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000ff;">$this</span>-&gt;<span style="color: #006600;">initView</span><span style="color: #66cc66;">(</span><span style="color: #66cc66;">)</span>;</div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #66cc66;">}</span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> myAction<span style="color: #66cc66;">(</span><span style="color: #66cc66;">)</span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #66cc66;">{</span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080; font-style: italic;">/**</span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #808080; font-style: italic;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;* default method of getting</span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #808080; font-style: italic;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;* Zend_Controller_Action_Helper_FlashMessenger instance</span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #808080; font-style: italic;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;* on-demand</span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #808080; font-style: italic;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;*/</span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000ff;">$this</span>-&gt;_flashMessenger-&gt;<span style="color: #006600;">addMessage</span><span style="color: #66cc66;">(</span><span style="color: #ff0000;">'Record Saved!'</span><span style="color: #66cc66;">)</span>;</div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #66cc66;">}</span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> myNextRequestAction<span style="color: #66cc66;">(</span><span style="color: #66cc66;">)</span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #66cc66;">{</span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000ff;">$this</span>-&gt;<span style="color: #006600;">view</span>-&gt;<span style="color: #006600;">messages</span> = <span style="color: #0000ff;">$this</span>-&gt;_flashMessenger-&gt;<span style="color: #006600;">getMessages</span><span style="color: #66cc66;">(</span><span style="color: #66cc66;">)</span>;</div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000ff;">$this</span>-&gt;<span style="color: #006600;">render</span><span style="color: #66cc66;">(</span><span style="color: #66cc66;">)</span>;</div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #66cc66;">}</span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #66cc66;">}</span></div></li></ol></div></div></div>

    </div>
</div>
        <div class="section" id="zend.controller.actionhelpers.json" name="zend.controller.actionhelpers.json"><div class="info"><h3>JSON</h3></div>
    

    <p class="para">
        <acronym class="acronym">JSON</acronym> responses are rapidly becoming the response of choice when dealing
        with <acronym class="acronym">AJAX</acronym> requests that expect dataset responses;
        <acronym class="acronym">JSON</acronym> can be immediately parsed on the client-side, leading to quick
        execution.
    </p>

    <div class="section" id="zend.controller.actionhelpers.json.usage" name="zend.controller.actionhelpers.json.usage"><div class="info"><h4>Usage</h4></div>
        

        <p class="para">
            Usage is simple: either call it as a method of the helper broker, or
            call one of the methods  <span class="methodname">encodeJson()</span> or
             <span class="methodname">sendJson()</span>:
        </p>

        <p class="para">
            direct($data, $sendNow = true, $keepLayouts = false, $encodeData = true)
        </p>

        <p class="para">
            sendJson($data, $keepLayouts = false, $encodeData = true)
        </p>

        <p class="para">
            encodeJson($data, $keepLayouts = false, $encodeData = true)
        </p>

        <ul class="itemizedlist"><li class="listitem">
                <p class="para">
                    <em class="emphasis">$data</em>: data to encode as JSON
                </p>
            </li>
            <li class="listitem">
                <p class="para">
                    <em class="emphasis">$sendNow</em>: flag to define whether
                    to send the JSON data immediately.  When true, the helper
                    will immediately set the respose body and exit.
                </p>
            </li>
            <li class="listitem">
                <p class="para">
                    <em class="emphasis">$keepLayouts</em>: flag to define whether
                    to enable or disable layours.  When false, all layouts
                    are disabled.  Optionally, this can be an array of options
                    to pass as the second argument to  <span class="methodname">Zend_Json::encode()</span>.
                    This array of options allows enabling layouts and encoding using
                   <span class="classname">Zend_Json_Expr</span>.
                </p>
            </li>
            <li class="listitem">
                <p class="para">
                    <em class="emphasis">$encodeData</em>: flag to define whether
                    <em class="emphasis">$data</em> is already JSON-encoded.  When
                    true, this helper will not encode <em class="emphasis">$data</em>
                    to JSON before sending.
                </p>
            </li>
        </ul><blockquote><p><b class="note">Note</b>: <span class="info"><b>Keeping Layouts</b><br></span>
            

            
                If you have a separate layout for <acronym class="acronym">JSON</acronym> responses -- perhaps to wrap
                the <acronym class="acronym">JSON</acronym> response in some sort of context -- each method in the
                <acronym class="acronym">JSON</acronym> helper accepts an optional argument <em class="emphasis">$keepLayouts</em>: a flag to enable or
                disable layouts. Passing a boolean <b><tt>TRUE</tt></b> value will keep
                layouts enabled:
            <br></p><div class="programlisting php"><div class="phpcode"><div class="php" style="font-family: monospace;"><ol><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #0000ff;">$this</span>-&gt;_helper-&gt;<span style="color: #006600;">json</span><span style="color: #66cc66;">(</span><span style="color: #0000ff;">$data</span>, <span style="color: #000000; font-weight: bold;">true</span><span style="color: #66cc66;">)</span>;</div></li></ol></div></div></div>


            
                Optionally, you can pass an array as the third parameter. This
                array may contain a variety of options, including the
                <em class="emphasis">keepLayouts</em> option:
            <br><div class="programlisting php"><div class="phpcode"><div class="php" style="font-family: monospace;"><ol><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #808080; font-style: italic;">// Direct helper call</span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #0000ff;">$this</span>-&gt;_helper-&gt;<span style="color: #006600;">json</span><span style="color: #66cc66;">(</span><span style="color: #0000ff;">$data</span>, <span style="color: #000000; font-weight: bold;">true</span>, <a href="http://www.php.net/array"><span style="color: #000066;">array</span></a><span style="color: #66cc66;">(</span><span style="color: #ff0000;">'keepLayouts'</span> =&gt; <span style="color: #000000; font-weight: bold;">true</span><span style="color: #66cc66;">)</span>;</div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #808080; font-style: italic;">// ...or, call a method of the helper</span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #0000ff;">$this</span>-&gt;_helper-&gt;<span style="color: #006600;">sendJson</span><span style="color: #66cc66;">(</span><span style="color: #0000ff;">$data</span>, <a href="http://www.php.net/array"><span style="color: #000066;">array</span></a><span style="color: #66cc66;">(</span><span style="color: #ff0000;">'keepLayouts'</span> =&gt; <span style="color: #000000; font-weight: bold;">true</span><span style="color: #66cc66;">)</span><span style="color: #66cc66;">)</span>;</div></li></ol></div></div></div>

        </blockquote>

        <blockquote><p><b class="note">Note</b>: <span class="info"><b>Enabling encoding using Zend_Json_Expr</b><br></span>
            

            
                 <span class="methodname">Zend_Json::encode()</span> allows the encoding of native
                <acronym class="acronym">JSON</acronym> expressions using <span class="classname">Zend_Json_Expr</span>
                objects. This option is disabled by default. To enable this option, pass a boolean
                <b><tt>TRUE</tt></b> value to the <em class="emphasis">enableJsonExprFinder</em>
                option:
            <br></p><div class="programlisting php"><div class="phpcode"><div class="php" style="font-family: monospace;"><ol><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #0000ff;">$this</span>-&gt;_helper-&gt;<span style="color: #006600;">json</span><span style="color: #66cc66;">(</span><span style="color: #0000ff;">$data</span>, <span style="color: #000000; font-weight: bold;">true</span>, <a href="http://www.php.net/array"><span style="color: #000066;">array</span></a><span style="color: #66cc66;">(</span><span style="color: #ff0000;">'enableJsonExprFinder'</span> =&gt; <span style="color: #000000; font-weight: bold;">true</span><span style="color: #66cc66;">)</span>;</div></li></ol></div></div></div>


            
                If you desire to do this, you <em class="emphasis">must</em> pass an
                array as the third argument. This also allows you to combine other
                options, such as the <em class="emphasis">keepLayouts</em> option. All such
                options are then passed to  <span class="methodname">Zend_Json::encode()</span>.
            <br><div class="programlisting php"><div class="phpcode"><div class="php" style="font-family: monospace;"><ol><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #0000ff;">$this</span>-&gt;_helper-&gt;<span style="color: #006600;">json</span><span style="color: #66cc66;">(</span><span style="color: #0000ff;">$data</span>, <span style="color: #000000; font-weight: bold;">true</span>, <a href="http://www.php.net/array"><span style="color: #000066;">array</span></a><span style="color: #66cc66;">(</span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #ff0000;">'enableJsonExprFinder'</span> =&gt; <span style="color: #000000; font-weight: bold;">true</span>,</div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #ff0000;">'keepLayouts'</span>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; =&gt; <span style="color: #000000; font-weight: bold;">true</span>,</div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #66cc66;">)</span><span style="color: #66cc66;">)</span>;</div></li></ol></div></div></div>

        </blockquote>
    </div>    

    <div class="section" id="zend.controller.actionhelpers.json.example" name="zend.controller.actionhelpers.json.example"><div class="info"><h4>Example</h4></div>
        

        <div class="programlisting php"><div class="phpcode"><div class="php" style="font-family: monospace;"><ol><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #000000; font-weight: bold;">class</span> FooController <span style="color: #000000; font-weight: bold;">extends</span> Zend_Controller_Action</div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #66cc66;">{</span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> barAction<span style="color: #66cc66;">(</span><span style="color: #66cc66;">)</span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #66cc66;">{</span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080; font-style: italic;">// do some processing...</span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080; font-style: italic;">// Send the JSON response:</span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000ff;">$this</span>-&gt;_helper-&gt;<span style="color: #006600;">json</span><span style="color: #66cc66;">(</span><span style="color: #0000ff;">$data</span><span style="color: #66cc66;">)</span>;</div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080; font-style: italic;">// or...</span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000ff;">$this</span>-&gt;_helper-&gt;<span style="color: #006600;">json</span>-&gt;<span style="color: #006600;">sendJson</span><span style="color: #66cc66;">(</span><span style="color: #0000ff;">$data</span><span style="color: #66cc66;">)</span>;</div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080; font-style: italic;">// or retrieve the json:</span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000ff;">$json</span> = <span style="color: #0000ff;">$this</span>-&gt;_helper-&gt;<span style="color: #006600;">json</span>-&gt;<span style="color: #006600;">encodeJson</span><span style="color: #66cc66;">(</span><span style="color: #0000ff;">$data</span><span style="color: #66cc66;">)</span>;</div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #66cc66;">}</span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #66cc66;">}</span></div></li></ol></div></div></div>

    </div>
    
</div>
        <div class="section" id="zend.controller.actionhelpers.redirector" name="zend.controller.actionhelpers.redirector"><div class="info"><h3>Redirector</h3></div>
    

    <div class="section" id="zend.controller.actionhelper.redirector.introduction" name="zend.controller.actionhelper.redirector.introduction"><div class="info"><h4>Introduction</h4></div>
        

        <p class="para">
            The <em class="emphasis">Redirector</em> helper allows you to use a redirector
            object to fulfill your application's needs for redirecting to a new
            <acronym class="acronym">URL</acronym>. It provides numerous benefits over the
             <span class="methodname">_redirect()</span> method, such as being able to preconfigure
            sitewide behavior into the redirector object or using the built in
             <span class="methodname">gotoSimple($action, $controller, $module, $params)</span> interface
            similar to that of  <span class="methodname">Zend_Controller_Action::_forward()</span>.
        </p>

        <p class="para">
            The <em class="emphasis">Redirector</em> has a number of methods that can be used
            to affect the behaviour at redirect:
        </p>

        <ul class="itemizedlist"><li class="listitem">
                <p class="para">
                     <span class="methodname">setCode()</span> can be used to set the
                    <acronym class="acronym">HTTP</acronym> response code to use during the redirect.
                </p>
            </li>

            <li class="listitem">
                <p class="para">
                     <span class="methodname">setExit()</span> can be used to force an
                     <span class="methodname">exit()</span> following a redirect. By default this is
                    <b><tt>TRUE</tt></b>.
                </p>
            </li>

            <li class="listitem">
                <p class="para">
                     <span class="methodname">setGotoSimple()</span> can be used to set a default
                    <acronym class="acronym">URL</acronym> to use if none is passed to
                     <span class="methodname">gotoSimple()</span>. Uses the <acronym class="acronym">API</acronym>
                    of  <span class="methodname">Zend_Controller_Action::_forward()</span>:
                     <span class="methodname">setGotoSimple($action, $controller = null, $module = null, array
                    $params = array())</span>
                </p>
            </li>

            <li class="listitem">
                <p class="para">
                     <span class="methodname">setGotoRoute()</span> can be used to set a
                    <acronym class="acronym">URL</acronym> based on a registered route. Pass in an array of
                    key / value pairs and a route name, and it will assemble the
                    <acronym class="acronym">URL</acronym> according to the route type and definition.
                </p>
            </li>

            <li class="listitem">
                <p class="para">
                     <span class="methodname">setGotoUrl()</span> can be used to set a default
                    <acronym class="acronym">URL</acronym> to
                    use if none is passed to  <span class="methodname">gotoUrl()</span>. Accepts a
                    single <acronym class="acronym">URL</acronym> string.
                </p>
            </li>

            <li class="listitem">
                <p class="para">
                     <span class="methodname">setPrependBase()</span> can be used to prepend the
                    request object's base <acronym class="acronym">URL</acronym> to a <acronym class="acronym">URL</acronym>
                    specified with
                     <span class="methodname">setGotoUrl()</span>,  <span class="methodname">gotoUrl()</span>, or
                     <span class="methodname">gotoUrlAndExit()</span>.
                </p>
            </li>

            <li class="listitem">
                <p class="para">
                     <span class="methodname">setUseAbsoluteUri()</span> can be used to force the
                    <em class="emphasis">Redirector</em> to use absolute <acronym class="acronym">URI</acronym>s when
                    redirecting. When this option is set, it uses the value of
                    <var class="varname">$_SERVER['HTTP_HOST']</var>,
                    <var class="varname">$_SERVER['SERVER_PORT']</var>, and
                    <var class="varname">$_SERVER['HTTPS']</var> to form a full <acronym class="acronym">URI</acronym>
                    to the <acronym class="acronym">URL</acronym>
                    specified by one of the redirect methods. This option is off
                    by default, but may be enabled by default in later releases.
                </p>
            </li>
        </ul><p class="para">
            Additionally, there are a variety of methods in the redirector for
            performing the actual redirects:
        </p>

        <ul class="itemizedlist"><li class="listitem">
                <p class="para">
                     <span class="methodname">gotoSimple()</span> uses
                     <span class="methodname">setGotoSimple()</span>
                    ( <span class="methodname">_forward()</span>-like <acronym class="acronym">API</acronym>) to build a
                    <acronym class="acronym">URL</acronym> and perform a redirect.
                </p>
            </li>

            <li class="listitem">
                <p class="para">
                     <span class="methodname">gotoRoute()</span> uses
                     <span class="methodname">setGotoRoute()</span>
                    (<em class="emphasis">route-assembly</em>) to build a <acronym class="acronym">URL</acronym> and
                    perform a redirect.
                </p>
            </li>

            <li class="listitem">
                <p class="para">
                     <span class="methodname">gotoUrl()</span> uses  <span class="methodname">setGotoUrl()</span>
                    (<em class="emphasis"><acronym class="acronym">URL</acronym> string</em>) to build a
                    <acronym class="acronym">URL</acronym> and perform a redirect.
                </p>
            </li>
        </ul><p class="para">
            Finally, you can determine the current redirect <acronym class="acronym">URL</acronym> at any time
            using  <span class="methodname">getRedirectUrl()</span>.
        </p>
    </div>

    <div class="section" id="zend.controller.actionhelper.redirector.basicusage" name="zend.controller.actionhelper.redirector.basicusage"><div class="info"><h4>Basic Usage Examples</h4></div>
        

        <div class="example"><div class="info"><p><b>Example #5 Setting Options</b></p></div>
            

            <div class="example-contents"><p>
                This example overrides several options, including setting the
                <acronym class="acronym">HTTP</acronym> status code to use in the redirect ('303'), not defaulting
                to exit on redirect, and defining a default <acronym class="acronym">URL</acronym> to use when
                redirecting.
            </p></div>

            <div class="programlisting php"><div class="phpcode"><div class="php" style="font-family: monospace;"><ol><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #000000; font-weight: bold;">class</span> SomeController <span style="color: #000000; font-weight: bold;">extends</span> Zend_Controller_Action</div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #66cc66;">{</span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #808080; font-style: italic;">/**</span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #808080; font-style: italic;">&nbsp; &nbsp; &nbsp;* Redirector - defined for code completion</span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #808080; font-style: italic;">&nbsp; &nbsp; &nbsp;*</span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #808080; font-style: italic;">&nbsp; &nbsp; &nbsp;* @var Zend_Controller_Action_Helper_Redirector</span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #808080; font-style: italic;">&nbsp; &nbsp; &nbsp;*/</span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; protected <span style="color: #0000ff;">$_redirector</span> = <span style="color: #000000; font-weight: bold;">null</span>;</div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> init<span style="color: #66cc66;">(</span><span style="color: #66cc66;">)</span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #66cc66;">{</span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000ff;">$this</span>-&gt;_redirector = <span style="color: #0000ff;">$this</span>-&gt;_helper-&gt;<span style="color: #006600;">getHelper</span><span style="color: #66cc66;">(</span><span style="color: #ff0000;">'Redirector'</span><span style="color: #66cc66;">)</span>;</div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080; font-style: italic;">// Set the default options for the redirector</span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080; font-style: italic;">// Since the object is registered in the helper broker, these</span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080; font-style: italic;">// become relevant for all actions from this point forward</span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000ff;">$this</span>-&gt;_redirector-&gt;<span style="color: #006600;">setCode</span><span style="color: #66cc66;">(</span><span style="color: #cc66cc;">303</span><span style="color: #66cc66;">)</span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; -&gt;<span style="color: #006600;">setExit</span><span style="color: #66cc66;">(</span><span style="color: #000000; font-weight: bold;">false</span><span style="color: #66cc66;">)</span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; -&gt;<span style="color: #006600;">setGotoSimple</span><span style="color: #66cc66;">(</span><span style="color: #ff0000;">"this-action"</span>,</div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #ff0000;">"some-controller"</span><span style="color: #66cc66;">)</span>;</div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #66cc66;">}</span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> myAction<span style="color: #66cc66;">(</span><span style="color: #66cc66;">)</span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #66cc66;">{</span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080; font-style: italic;">/* do some stuff */</span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080; font-style: italic;">// Redirect to a previously registered URL, and force an exit</span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080; font-style: italic;">// to occur when done:</span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000ff;">$this</span>-&gt;_redirector-&gt;<span style="color: #006600;">redirectAndExit</span><span style="color: #66cc66;">(</span><span style="color: #66cc66;">)</span>;</div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">return</span>; <span style="color: #808080; font-style: italic;">// never reached</span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #66cc66;">}</span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #66cc66;">}</span></div></li></ol></div></div></div>

        </div>

        <div class="example"><div class="info"><p><b>Example #6 Using Defaults</b></p></div>
            

            <div class="example-contents"><p>
                This example assumes that the defaults are used, which means
                that any redirect will result in an immediate
                 <span class="methodname">exit()</span>.
            </p></div>

            <div class="programlisting php"><div class="phpcode"><div class="php" style="font-family: monospace;"><ol><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #808080; font-style: italic;">// ALTERNATIVE EXAMPLE</span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #000000; font-weight: bold;">class</span> AlternativeController <span style="color: #000000; font-weight: bold;">extends</span> Zend_Controller_Action</div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #66cc66;">{</span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #808080; font-style: italic;">/**</span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #808080; font-style: italic;">&nbsp; &nbsp; &nbsp;* Redirector - defined for code completion</span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #808080; font-style: italic;">&nbsp; &nbsp; &nbsp;*</span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #808080; font-style: italic;">&nbsp; &nbsp; &nbsp;* @var Zend_Controller_Action_Helper_Redirector</span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #808080; font-style: italic;">&nbsp; &nbsp; &nbsp;*/</span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; protected <span style="color: #0000ff;">$_redirector</span> = <span style="color: #000000; font-weight: bold;">null</span>;</div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> init<span style="color: #66cc66;">(</span><span style="color: #66cc66;">)</span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #66cc66;">{</span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000ff;">$this</span>-&gt;_redirector = <span style="color: #0000ff;">$this</span>-&gt;_helper-&gt;<span style="color: #006600;">getHelper</span><span style="color: #66cc66;">(</span><span style="color: #ff0000;">'Redirector'</span><span style="color: #66cc66;">)</span>;</div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #66cc66;">}</span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> myAction<span style="color: #66cc66;">(</span><span style="color: #66cc66;">)</span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #66cc66;">{</span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080; font-style: italic;">/* do some stuff */</span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000ff;">$this</span>-&gt;_redirector</div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; -&gt;<span style="color: #006600;">gotoUrl</span><span style="color: #66cc66;">(</span><span style="color: #ff0000;">'/my-controller/my-action/param1/test/param2/test2'</span><span style="color: #66cc66;">)</span>;</div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">return</span>; <span style="color: #808080; font-style: italic;">// never reached since default is to goto and exit</span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #66cc66;">}</span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #66cc66;">}</span></div></li></ol></div></div></div>

        </div>

        <div class="example"><div class="info"><p><b>Example #7 Using goto()'s _forward() API</b></p></div>
            

            <div class="example-contents"><p>
                 <span class="methodname">gotoSimple()</span>'s <acronym class="acronym">API</acronym> mimics that of
                 <span class="methodname">Zend_Controller_Action::_forward()</span>. The primary
                difference is that it builds a <acronym class="acronym">URL</acronym> from the parameters passed,
                and using the default <var class="filename">:module/:controller/:action/*</var>
                format of the default router. It then redirects instead of
                chaining the action.
            </p></div>

            <div class="programlisting php"><div class="phpcode"><div class="php" style="font-family: monospace;"><ol><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #000000; font-weight: bold;">class</span> ForwardController <span style="color: #000000; font-weight: bold;">extends</span> Zend_Controller_Action</div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #66cc66;">{</span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #808080; font-style: italic;">/**</span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #808080; font-style: italic;">&nbsp; &nbsp; &nbsp;* Redirector - defined for code completion</span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #808080; font-style: italic;">&nbsp; &nbsp; &nbsp;*</span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #808080; font-style: italic;">&nbsp; &nbsp; &nbsp;* @var Zend_Controller_Action_Helper_Redirector</span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #808080; font-style: italic;">&nbsp; &nbsp; &nbsp;*/</span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; protected <span style="color: #0000ff;">$_redirector</span> = <span style="color: #000000; font-weight: bold;">null</span>;</div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> init<span style="color: #66cc66;">(</span><span style="color: #66cc66;">)</span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #66cc66;">{</span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000ff;">$this</span>-&gt;_redirector = <span style="color: #0000ff;">$this</span>-&gt;_helper-&gt;<span style="color: #006600;">getHelper</span><span style="color: #66cc66;">(</span><span style="color: #ff0000;">'Redirector'</span><span style="color: #66cc66;">)</span>;</div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #66cc66;">}</span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> myAction<span style="color: #66cc66;">(</span><span style="color: #66cc66;">)</span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #66cc66;">{</span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080; font-style: italic;">/* do some stuff */</span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080; font-style: italic;">// Redirect to 'my-action' of 'my-controller' in the current</span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080; font-style: italic;">// module, using the params param1 =&gt; test and param2 =&gt; test2</span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000ff;">$this</span>-&gt;_redirector-&gt;<span style="color: #006600;">gotoSimple</span><span style="color: #66cc66;">(</span><span style="color: #ff0000;">'my-action'</span>,</div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #ff0000;">'my-controller'</span>,</div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #000000; font-weight: bold;">null</span>,</div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<a href="http://www.php.net/array"><span style="color: #000066;">array</span></a><span style="color: #66cc66;">(</span><span style="color: #ff0000;">'param1'</span> =&gt; <span style="color: #ff0000;">'test'</span>,</div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 
&nbsp; &nbsp;<span style="color: #ff0000;">'param2'</span> =&gt; <span style="color: #ff0000;">'test2'</span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 
&nbsp; &nbsp;<span style="color: #66cc66;">)</span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #66cc66;">)</span>;</div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #66cc66;">}</span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #66cc66;">}</span></div></li></ol></div></div></div>

        </div>

        <div class="example"><div class="info"><p><b>Example #8 Using Route Assembly with gotoRoute()</b></p></div>
            

            <div class="example-contents"><p>
                The following example uses the <a href="http://framework.zend.com/manual/1.12/en/zend.controller.router.html" class="link">router's</a>
                 <span class="methodname">assemble()</span> method to create a <acronym class="acronym">URL</acronym>
                based on an associative array of parameters passed. It assumes the following
                route has been registered:
            </p></div>

            <div class="programlisting php"><div class="phpcode"><div class="php" style="font-family: monospace;"><ol><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #0000ff;">$route</span> = <span style="color: #000000; font-weight: bold;">new</span> Zend_Controller_Router_Route<span style="color: #66cc66;">(</span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #ff0000;">'blog/:year/:month/:day/:id'</span>,</div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <a href="http://www.php.net/array"><span style="color: #000066;">array</span></a><span style="color: #66cc66;">(</span><span style="color: #ff0000;">'controller'</span> =&gt; <span style="color: #ff0000;">'archive'</span>,</div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #ff0000;">'module'</span> =&gt; <span style="color: #ff0000;">'blog'</span>,</div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #ff0000;">'action'</span> =&gt; <span style="color: #ff0000;">'view'</span><span style="color: #66cc66;">)</span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #66cc66;">)</span>;</div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #0000ff;">$router</span>-&gt;<span style="color: #006600;">addRoute</span><span style="color: #66cc66;">(</span><span style="color: #ff0000;">'blogArchive'</span>, <span style="color: #0000ff;">$route</span><span style="color: #66cc66;">)</span>;</div></li></ol></div></div></div>


            <div class="example-contents"><p>
                Given an array with year set to 2006, month to 4, day to 24, and
                id to 42, it would then build the <acronym class="acronym">URL</acronym>
                <var class="filename">/blog/2006/4/24/42</var>.
            </p></div>

            <div class="programlisting php"><div class="phpcode"><div class="php" style="font-family: monospace;"><ol><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #000000; font-weight: bold;">class</span> BlogAdminController <span style="color: #000000; font-weight: bold;">extends</span> Zend_Controller_Action</div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #66cc66;">{</span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #808080; font-style: italic;">/**</span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #808080; font-style: italic;">&nbsp; &nbsp; &nbsp;* Redirector - defined for code completion</span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #808080; font-style: italic;">&nbsp; &nbsp; &nbsp;*</span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #808080; font-style: italic;">&nbsp; &nbsp; &nbsp;* @var Zend_Controller_Action_Helper_Redirector</span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #808080; font-style: italic;">&nbsp; &nbsp; &nbsp;*/</span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; protected <span style="color: #0000ff;">$_redirector</span> = <span style="color: #000000; font-weight: bold;">null</span>;</div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> init<span style="color: #66cc66;">(</span><span style="color: #66cc66;">)</span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #66cc66;">{</span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000ff;">$this</span>-&gt;_redirector = <span style="color: #0000ff;">$this</span>-&gt;_helper-&gt;<span style="color: #006600;">getHelper</span><span style="color: #66cc66;">(</span><span style="color: #ff0000;">'Redirector'</span><span style="color: #66cc66;">)</span>;</div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #66cc66;">}</span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> returnAction<span style="color: #66cc66;">(</span><span style="color: #66cc66;">)</span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #66cc66;">{</span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080; font-style: italic;">/* do some stuff */</span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080; font-style: italic;">// Redirect to blog archive. Builds the following URL:</span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080; font-style: italic;">// /blog/2006/4/24/42</span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000ff;">$this</span>-&gt;_redirector-&gt;<span style="color: #006600;">gotoRoute</span><span style="color: #66cc66;">(</span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <a href="http://www.php.net/array"><span style="color: #000066;">array</span></a><span style="color: #66cc66;">(</span><span style="color: #ff0000;">'year'</span> =&gt; <span style="color: #cc66cc;">2006</span>,</div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #ff0000;">'month'</span> =&gt; <span style="color: #cc66cc;">4</span>,</div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #ff0000;">'day'</span> =&gt; <span style="color: #cc66cc;">24</span>,</div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #ff0000;">'id'</span> =&gt; <span style="color: #cc66cc;">42</span><span style="color: #66cc66;">)</span>,</div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #ff0000;">'blogArchive'</span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">)</span>;</div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #66cc66;">}</span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #66cc66;">}</span></div></li></ol></div></div></div>

        </div>
    </div>
</div>
        <div class="section" id="zend.controller.actionhelpers.viewrenderer" name="zend.controller.actionhelpers.viewrenderer"><div class="info"><h3>ViewRenderer</h3></div>
    

    <div class="section" id="zend.controller.actionhelper.viewrenderer.introduction" name="zend.controller.actionhelper.viewrenderer.introduction"><div class="info"><h4>Introduction</h4></div>
        

        <p class="para">
            The <em class="emphasis">ViewRenderer</em> helper is designed to satisfy the
            following goals:
        </p>

        <ul class="itemizedlist"><li class="listitem">
                <p class="para">
                    Eliminate the need to instantiate view objects within
                    controllers; view objects will be automatically registered
                    with the controller.
                </p>
            </li>

            <li class="listitem">
                <p class="para">
                    Automatically set view script, helper, and filter paths
                    based on the current module, and automatically associate
                    the current module name as a class prefix for helper and
                    filter classes.
                </p>
            </li>

            <li class="listitem">
                <p class="para">
                    Create a globally available view object for all dispatched
                    controllers and actions.
                </p>
            </li>

            <li class="listitem">
                <p class="para">
                    Allow the developer to set default view rendering options
                    for all controllers.
                </p>
            </li>

            <li class="listitem">
                <p class="para">
                    Add the ability to automatically render a view script with
                    no intervention.
                </p>
            </li>

            <li class="listitem">
                <p class="para">
                    Allow the developer to create her own specifications for
                    the view base path and for view script paths.
                </p>
            </li>
        </ul><blockquote><p><b class="note">Note</b>: 
            
                If you perform a  <span class="methodname">_forward()</span>,
                 <span class="methodname">redirect()</span>, or
                 <span class="methodname">render()</span> manually, autorendering will not occur, as
                by performing any of these actions you are telling the
                <em class="emphasis">ViewRenderer</em> that you are determining your own
                output.
            <br></p></blockquote>

        <blockquote><p><b class="note">Note</b>: 
            
                The <em class="emphasis">ViewRenderer</em> is enabled by default. You may
                disable it via the front controller <em class="emphasis">noViewRenderer</em>
                param (<strong class="command">$front-&gt;setParam('noViewRenderer', true);</strong>) or
                removing the helper from the helper broker stack
                ( <span class="methodname">Zend_Controller_Action_HelperBroker::removeHelper('viewRenderer')</span>).
            <br>

            
                If you wish to modify settings of the <em class="emphasis">ViewRenderer</em>
                prior to dispatching the front controller, you may do so in one
                of two ways:
            <br></p><ul class="itemizedlist"><li class="listitem">
                    <p class="para">
                        Instantiate and register your own
                        <em class="emphasis">ViewRenderer</em> object and pass it to the
                        helper broker:
                    </p>

                    <div class="programlisting php"><div class="phpcode"><div class="php" style="font-family: monospace;"><ol><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #0000ff;">$viewRenderer</span> = <span style="color: #000000; font-weight: bold;">new</span> Zend_Controller_Action_Helper_ViewRenderer<span style="color: #66cc66;">(</span><span style="color: #66cc66;">)</span>;</div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #0000ff;">$viewRenderer</span>-&gt;<span style="color: #006600;">setView</span><span style="color: #66cc66;">(</span><span style="color: #0000ff;">$view</span><span style="color: #66cc66;">)</span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;-&gt;<span style="color: #006600;">setViewSuffix</span><span style="color: #66cc66;">(</span><span style="color: #ff0000;">'php'</span><span style="color: #66cc66;">)</span>;</div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">Zend_Controller_Action_HelperBroker::<span style="color: #006600;">addHelper</span><span style="color: #66cc66;">(</span><span style="color: #0000ff;">$viewRenderer</span><span style="color: #66cc66;">)</span>;</div></li></ol></div></div></div>

                </li>

                <li class="listitem">
                    <p class="para">
                        Initialize and/or retrieve a <em class="emphasis">ViewRenderer</em>
                        object on demand via the helper broker:
                    </p>

                    <div class="programlisting php"><div class="phpcode"><div class="php" style="font-family: monospace;"><ol><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #0000ff;">$viewRenderer</span> =</div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; Zend_Controller_Action_HelperBroker::<span style="color: #006600;">getStaticHelper</span><span style="color: #66cc66;">(</span><span style="color: #ff0000;">'viewRenderer'</span><span style="color: #66cc66;">)</span>;</div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #0000ff;">$viewRenderer</span>-&gt;<span style="color: #006600;">setView</span><span style="color: #66cc66;">(</span><span style="color: #0000ff;">$view</span><span style="color: #66cc66;">)</span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;-&gt;<span style="color: #006600;">setViewSuffix</span><span style="color: #66cc66;">(</span><span style="color: #ff0000;">'php'</span><span style="color: #66cc66;">)</span>;</div></li></ol></div></div></div>

                </li>
            </ul></blockquote>
    </div>

    <div class="section" id="zend.controller.actionhelper.viewrenderer.api" name="zend.controller.actionhelper.viewrenderer.api"><div class="info"><h4>API</h4></div>
        

        <p class="para">
            At its most basic usage, you simply instantiate the
            <em class="emphasis">ViewRenderer</em> and pass it to the action helper broker.
            The easiest way to instantiate it and register in one go is to use
            the helper broker's  <span class="methodname">getStaticHelper()</span> method:
        </p>

        <div class="programlisting php"><div class="phpcode"><div class="php" style="font-family: monospace;"><ol><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">Zend_Controller_Action_HelperBroker::<span style="color: #006600;">getStaticHelper</span><span style="color: #66cc66;">(</span><span style="color: #ff0000;">'viewRenderer'</span><span style="color: #66cc66;">)</span>;</div></li></ol></div></div></div>


        <p class="para">
            The first time an action controller is instantiated, it will trigger
            the <em class="emphasis">ViewRenderer</em> to instantiate a view object. Each
            time a controller is instantiated, the <em class="emphasis">ViewRenderer</em>'s
             <span class="methodname">init()</span> method is called, which will cause it to set the
            view property of the action controller, and call
             <span class="methodname">addScriptPath()</span> with a path relative to the current
            module; this will be called with a class prefix named after the
            current module, effectively namespacing all helper and filter
            classes you define for the module.
        </p>

        <p class="para">
            Each time  <span class="methodname">postDispatch()</span> is called, it will call
             <span class="methodname">render()</span> for the current action.
        </p>

        <p class="para">
            As an example, consider the following class:
        </p>

        <div class="programlisting php"><div class="phpcode"><div class="php" style="font-family: monospace;"><ol><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #808080; font-style: italic;">// A controller class, foo module:</span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #000000; font-weight: bold;">class</span> Foo_BarController <span style="color: #000000; font-weight: bold;">extends</span> Zend_Controller_Action</div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #66cc66;">{</span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #808080; font-style: italic;">// Render bar/index.phtml by default; no action required</span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> indexAction<span style="color: #66cc66;">(</span><span style="color: #66cc66;">)</span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #66cc66;">{</span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #66cc66;">}</span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #808080; font-style: italic;">// Render bar/populate.phtml with variable 'foo' set to 'bar'.</span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #808080; font-style: italic;">// Since view object defined at preDispatch(), it's already available.</span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> populateAction<span style="color: #66cc66;">(</span><span style="color: #66cc66;">)</span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #66cc66;">{</span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000ff;">$this</span>-&gt;<span style="color: #006600;">view</span>-&gt;<span style="color: #006600;">foo</span> = <span style="color: #ff0000;">'bar'</span>;</div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #66cc66;">}</span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #66cc66;">}</span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">...</div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #808080; font-style: italic;">// in one of your view scripts:</span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #0000ff;">$this</span>-&gt;<span style="color: #006600;">foo</span><span style="color: #66cc66;">(</span><span style="color: #66cc66;">)</span>; <span style="color: #808080; font-style: italic;">// call Foo_View_Helper_Foo::foo()</span></div></li></ol></div></div></div>


        <p class="para">
            The <em class="emphasis">ViewRenderer</em> also defines a number of accessors to
            allow setting and retrieving view options:
        </p>

        <ul class="itemizedlist"><li class="listitem">
                <p class="para">
                     <span class="methodname">setView($view)</span> allows you to set the view
                    object for the <em class="emphasis">ViewRenderer</em>. It gets set as
                    the public class property <var class="varname">$view</var>.
                </p>
            </li>

            <li class="listitem">
                <p class="para">
                     <span class="methodname">setNeverRender($flag = true)</span> can be used to
                    disable or enable autorendering globally, i.e., for all
                    controllers. If set to <b><tt>TRUE</tt></b>,
                     <span class="methodname">postDispatch()</span>
                    will not automatically call  <span class="methodname">render()</span> in the
                    current controller.  <span class="methodname">getNeverRender()</span> retrieves
                    the current value.
                </p>
            </li>

            <li class="listitem">
                <p class="para">
                     <span class="methodname">setNoRender($flag = true)</span> can be used to
                    disable or enable autorendering. If set to <b><tt>TRUE</tt></b>,
                     <span class="methodname">postDispatch()</span> will not automatically call
                     <span class="methodname">render()</span> in the current controller. This
                    setting is reset each time  <span class="methodname">preDispatch()</span> is
                    called (i.e., you need to set this flag for each controller
                    for which you don't want autorenderering to occur).
                     <span class="methodname">getNoRender()</span> retrieves the current value.
                </p>
            </li>

            <li class="listitem">
                <p class="para">
                     <span class="methodname">setNoController($flag = true)</span> can be used to
                    tell  <span class="methodname">render()</span> not to look for the action script
                    in a subdirectory named after the controller (which is the
                    default behaviour).  <span class="methodname">getNoController()</span> retrieves
                    the current value.
                </p>
            </li>

            <li class="listitem">
                <p class="para">
                     <span class="methodname">setNeverController($flag = true)</span> is analogous
                    to  <span class="methodname">setNoController()</span>, but works on a global
                    level -- i.e., it will not be reset for each dispatched
                    action.  <span class="methodname">getNeverController()</span> retrieves
                    the current value.
                </p>
            </li>

            <li class="listitem">
                <p class="para">
                     <span class="methodname">setScriptAction($name)</span> can be used to
                    specify the action script to render. <var class="varname">$name</var>
                    should be the name of the script minus the file suffix (and
                    without the controller subdirectory, unless
                    <em class="emphasis">noController</em> has been turned on). If not
                    specified, it looks for a view script named after the action
                    in the request object.  <span class="methodname">getScriptAction()</span>
                    retrieves the current value.
                </p>
            </li>

            <li class="listitem">
                <p class="para">
                     <span class="methodname">setResponseSegment($name)</span> can be used to
                    specify which response object named segment to render into.
                    If not specified, it renders into the default segment.
                     <span class="methodname">getResponseSegment()</span> retrieves the current
                    value.
                </p>
            </li>

            <li class="listitem">
                <p class="para">
                     <span class="methodname">initView($path, $prefix, $options)</span> may be called
                    to specify the base view path, class prefix for helper and
                    filter scripts, and <em class="emphasis">ViewRenderer</em> options. You
                    may pass any of the following flags:
                    <em class="emphasis">neverRender</em>, <em class="emphasis">noRender</em>,
                    <em class="emphasis">noController</em>, <em class="emphasis">scriptAction</em>, and
                    <em class="emphasis">responseSegment</em>.
                </p>
            </li>

            <li class="listitem">
                <p class="para">
                     <span class="methodname">setRender($action = null, $name = null, $noController
                        = false)</span> allows you to set any of
                    <em class="emphasis">scriptAction</em>, <em class="emphasis">responseSegment</em>, and
                    <em class="emphasis">noController</em> in one pass.  <span class="methodname">direct()</span>
                    is an alias to this method, allowing you to call this method
                    easily from your controller:
                </p>

                <div class="programlisting php"><div class="phpcode"><div class="php" style="font-family: monospace;"><ol><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #808080; font-style: italic;">// Render 'foo' instead of current action script</span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #0000ff;">$this</span>-&gt;_helper-&gt;<span style="color: #006600;">viewRenderer</span><span style="color: #66cc66;">(</span><span style="color: #ff0000;">'foo'</span><span style="color: #66cc66;">)</span>;</div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #808080; font-style: italic;">// render form.phtml to the 'html' response segment, without using a</span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #808080; font-style: italic;">// controller view script subdirectory:</span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #0000ff;">$this</span>-&gt;_helper-&gt;<span style="color: #006600;">viewRenderer</span><span style="color: #66cc66;">(</span><span style="color: #ff0000;">'form'</span>, <span style="color: #ff0000;">'html'</span>, <span style="color: #000000; font-weight: bold;">true</span><span style="color: #66cc66;">)</span>;</div></li></ol></div></div></div>


                <blockquote><p><b class="note">Note</b>: 
                    
                         <span class="methodname">setRender()</span> and  <span class="methodname">direct()</span>
                        don't actually render the view script, but instead set hints
                        that  <span class="methodname">postDispatch()</span> and
                         <span class="methodname">render()</span> will use to render the view.
                    <br></p></blockquote>
            </li>
        </ul><p class="para">
            The constructor allows you to optionally pass the view object and
            <em class="emphasis">ViewRenderer</em> options; it accepts the same flags as
             <span class="methodname">initView()</span>:
        </p>

        <div class="programlisting php"><div class="phpcode"><div class="php" style="font-family: monospace;"><ol><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #0000ff;">$view</span>&nbsp; &nbsp; = <span style="color: #000000; font-weight: bold;">new</span> Zend_View<span style="color: #66cc66;">(</span><a href="http://www.php.net/array"><span style="color: #000066;">array</span></a><span style="color: #66cc66;">(</span><span style="color: #ff0000;">'encoding'</span> =&gt; <span style="color: #ff0000;">'UTF-8'</span><span style="color: #66cc66;">)</span><span style="color: #66cc66;">)</span>;</div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #0000ff;">$options</span> = <a href="http://www.php.net/array"><span style="color: #000066;">array</span></a><span style="color: #66cc66;">(</span><span style="color: #ff0000;">'noController'</span> =&gt; <span style="color: #000000; font-weight: bold;">true</span>, <span style="color: #ff0000;">'neverRender'</span> =&gt; <span style="color: #000000; font-weight: bold;">true</span><span style="color: #66cc66;">)</span>;</div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #0000ff;">$viewRenderer</span> =</div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">new</span> Zend_Controller_Action_Helper_ViewRenderer<span style="color: #66cc66;">(</span><span style="color: #0000ff;">$view</span>, <span style="color: #0000ff;">$options</span><span style="color: #66cc66;">)</span>;</div></li></ol></div></div></div>


        <p class="para">
            There are several additional methods for customizing path
            specifications used for determining the view base path to add to the
            view object, and the view script path to use when autodetermining
            the view script to render. These methods each take one or more of
            the following placeholders:
        </p>

        <ul class="itemizedlist"><li class="listitem">
                <p class="para">
                    <em class="emphasis">:moduleDir</em> refers to the current module's base
                    directory (by convention, the parent directory of the
                    module's controller directory).
                </p>
            </li>

            <li class="listitem">
                <p class="para">
                    <em class="emphasis">:module</em> refers to the current module name.
                </p>
            </li>

            <li class="listitem">
                <p class="para">
                    <em class="emphasis">:controller</em> refers to the current controller name.
                </p>
            </li>

            <li class="listitem">
                <p class="para">
                    <em class="emphasis">:action</em> refers to the current action name.
                </p>
            </li>

            <li class="listitem">
                <p class="para">
                    <em class="emphasis">:suffix</em> refers to the view script suffix (which
                    may be set via  <span class="methodname">setViewSuffix()</span>).
                </p>
            </li>
        </ul><p class="para">
            The methods for controlling path specifications are:
        </p>

        <ul class="itemizedlist"><li class="listitem">
                <p class="para">
                     <span class="methodname">setViewBasePathSpec($spec)</span> allows you to change
                    the path specification used to determine the base path to
                    add to the view object. The default specification is
                    <var class="filename">:moduleDir/views</var>. You may retrieve the current
                    specification at any time using
                     <span class="methodname">getViewBasePathSpec()</span>.
                </p>
            </li>

            <li class="listitem">
                <p class="para">
                     <span class="methodname">setViewScriptPathSpec($spec)</span> allows you to
                    change the path specification used to determine the path to
                    an individual view script (minus the base view script path).
                    The default specification is
                    <var class="filename">:controller/:action.:suffix</var>. You may retrieve
                    the current specification at any time using
                     <span class="methodname">getViewScriptPathSpec()</span>.
                </p>
            </li>

            <li class="listitem">
                <p class="para">
                     <span class="methodname">setViewScriptPathNoControllerSpec($spec)</span> allows
                    you to change the path specification used to determine the
                    path to an individual view script when
                    <em class="emphasis">noController</em> is in effect (minus the base view
                    script path). The default specification is
                    <var class="filename">:action.:suffix</var>. You may retrieve the current
                    specification at any time using
                     <span class="methodname">getViewScriptPathNoControllerSpec()</span>.
                </p>
            </li>
        </ul><p class="para">
            For fine-grained control over path specifications, you may use
            <a href="http://framework.zend.com/manual/1.12/en/zend.filter.inflector.html" class="link">Zend_Filter_Inflector</a>.
            Under the hood, the <em class="emphasis">ViewRenderer</em> uses an inflector to
            perform path mappings already. To interact with the inflector --
            either to set your own for use, or to modify the default inflector,
            the following methods may be used:
        </p>

        <ul class="itemizedlist"><li class="listitem">
                <p class="para">
                     <span class="methodname">getInflector()</span> will retrieve the inflector. If
                    none exists yet in the <em class="emphasis">ViewRenderer</em>, it creates
                    one using the default rules.
                </p>

                <p class="para">
                    By default, it uses static rule references for the suffix
                    and module directory, as well as a static target; this
                    allows various <em class="emphasis">ViewRenderer</em> properties the
                    ability to dynamically modify the inflector.
                </p>
            </li>

            <li class="listitem">
                <p class="para">
                     <span class="methodname">setInflector($inflector, $reference)</span> allows you
                    to set a custom inflector for use with the
                    <em class="emphasis">ViewRenderer</em>. If <var class="varname">$reference</var> is
                    <b><tt>TRUE</tt></b>, it will set the suffix and module directory as static
                    references to <em class="emphasis">ViewRenderer</em> properties, as well
                    as the target.
                </p>
            </li>
        </ul><blockquote><p><b class="note">Note</b>: <span class="info"><b>Default Lookup Conventions</b><br></span>
            

            
                The <em class="emphasis">ViewRenderer</em> does some path normalization to
                make view script lookups easier. The default rules are as
                follows:
            <br></p><ul class="itemizedlist"><li class="listitem">
                    <p class="para">
                        <em class="emphasis">:module</em>: MixedCase and camelCasedWords are separated by
                        dashes, and the entire string cast to lowercase. E.g.:
                        "FooBarBaz" becomes "foo-bar-baz".
                    </p>

                    <p class="para">
                        Internally, the inflector uses the filters
                        <span class="classname">Zend_Filter_Word_CamelCaseToDash</span> and
                        <span class="classname">Zend_Filter_StringToLower</span>.
                    </p>
                </li>

                <li class="listitem">
                    <p class="para">
                        <em class="emphasis">:controller</em>: MixedCase and camelCasedWords are
                        separated by dashes; underscores are converted to directory
                        separators, and the entire string cast to lower case.
                        Examples: "<span class="classname">FooBar</span>" becomes "foo-bar";
                        "<span class="classname">FooBar_Admin</span>" becomes
                        "<var class="filename">foo-bar/admin</var>".
                    </p>

                    <p class="para">
                        Internally, the inflector uses the filters
                        <span class="classname">Zend_Filter_Word_CamelCaseToDash</span>,
                        <span class="classname">Zend_Filter_Word_UnderscoreToSeparator</span>, and
                        <span class="classname">Zend_Filter_StringToLower</span>.
                    </p>
                </li>

                <li class="listitem">
                    <p class="para">
                        <em class="emphasis">:action</em>: MixedCase and camelCasedWords are separated
                        by dashes; non-alphanumeric characters are translated to
                        dashes, and the entire string cast to lower case.
                        Examples: "fooBar" becomes "foo-bar"; "foo-barBaz"
                        becomes "foo-bar-baz".
                    </p>

                    <p class="para">
                        Internally, the inflector uses the filters
                        <span class="classname">Zend_Filter_Word_CamelCaseToDash</span>,
                        <span class="classname">Zend_Filter_PregReplace</span>, and
                        <span class="classname">Zend_Filter_StringToLower</span>.
                    </p>
                </li>
            </ul></blockquote>

        <p class="para">
            The final items in the <em class="emphasis">ViewRenderer</em> <acronym class="acronym">API</acronym> are the
            methods for actually determining view script paths and rendering views.
            These include:
        </p>

        <ul class="itemizedlist"><li class="listitem">
                <p class="para">
                     <span class="methodname">renderScript($script, $name)</span> allows you to
                    render a script with a path you specify, optionally to a
                    named path segment. When using this method, the
                    <em class="emphasis">ViewRenderer</em> does no autodetermination of the
                    script name, but instead directly passes the
                    <var class="varname">$script</var> argument directly to the view object's
                     <span class="methodname">render()</span> method.
                </p>

                <blockquote><p><b class="note">Note</b>: 
                    
                        Once the view has been rendered to the response object, it
                        sets the <em class="emphasis">noRender</em> to prevent accidentally
                        rendering the same view script multiple times.
                    <br></p></blockquote>

                <blockquote><p><b class="note">Note</b>: 
                    
                        By default,
                         <span class="methodname">Zend_Controller_Action::renderScript()</span>
                        proxies to the <em class="emphasis">ViewRenderer</em>'s
                         <span class="methodname">renderScript()</span> method.
                    <br></p></blockquote>
            </li>

            <li class="listitem">
                <p class="para">
                     <span class="methodname">getViewScript($action, $vars)</span> creates the path
                    to a view script based on the action passed and/or any
                    variables passed in <var class="varname">$vars</var>. Keys for this array
                    may include any of the path specification keys ('moduleDir',
                    'module', 'controller', 'action', and 'suffix'). Any
                    variables passed will be used; otherwise, values based on
                    the current request will be utlized.
                </p>

                <p class="para">
                     <span class="methodname">getViewScript()</span> will use either the
                    <em class="emphasis">viewScriptPathSpec</em> or
                    <em class="emphasis">viewScriptPathNoControllerSpec</em> based on the
                    setting of the <em class="emphasis">noController</em> flag.
                </p>

                <p class="para">
                    Word delimiters occurring in module, controller, or action names will be
                    replaced with dashes ('-'). Thus, if you have the controller name
                    '<strong class="command">foo.bar</strong>' and the action '<strong class="command">baz:bat</strong>', using
                    the default path specification will result in a view script path of
                    '<var class="filename">foo-bar/baz-bat.phtml</var>'.
                </p>

                <blockquote><p><b class="note">Note</b>: 
                    
                        By default,
                         <span class="methodname">Zend_Controller_Action::getViewScript()</span>
                        proxies to the <em class="emphasis">ViewRenderer</em>'s
                         <span class="methodname">getViewScript()</span> method.
                    <br></p></blockquote>
            </li>

            <li class="listitem">
                <p class="para">
                     <span class="methodname">render($action, $name, $noController)</span> checks
                    first to see if either <var class="varname">$name</var> or
                    <var class="varname">$noController</var> have been passed, and if so, sets
                    the appropriate flags (responseSegment and noController,
                    respectively) in the ViewRenderer. It then passes the
                    <var class="varname">$action</var> argument, if any, on to
                     <span class="methodname">getViewScript()</span>. Finally, it passes the
                    calculated view script path to  <span class="methodname">renderScript()</span>.
                </p>

                <blockquote><p><b class="note">Note</b>: 
                    
                        Be aware of the side-effects of using  <span class="methodname">render()</span>: the
                        values you pass for the response segment name and for
                        the noController flag will persist in the object.
                        Additionally, noRender will be set after rendering is
                        completed.
                    <br></p></blockquote>

                <blockquote><p><b class="note">Note</b>: 
                    
                        By default,
                         <span class="methodname">Zend_Controller_Action::render()</span> proxies to
                        the <em class="emphasis">ViewRenderer</em>'s  <span class="methodname">render()</span>
                        method.
                    <br></p></blockquote>
            </li>

            <li class="listitem">
                <p class="para">
                     <span class="methodname">renderBySpec($action, $vars, $name)</span> allows you
                    to pass path specification variables in order to determine
                    the view script path to create. It passes
                    <var class="varname">$action</var> and <var class="varname">$vars</var> to
                     <span class="methodname">getScriptPath()</span>, and then passes the resulting
                    script path and <var class="varname">$name</var> on to
                     <span class="methodname">renderScript()</span>.
                </p>
            </li>
        </ul></div>

    <div class="section" id="zend.controller.actionhelper.viewrenderer.basicusage" name="zend.controller.actionhelper.viewrenderer.basicusage"><div class="info"><h4>Basic Usage Examples</h4></div>
        

        <div class="example"><div class="info"><p><b>Example #9 Basic Usage</b></p></div>
            

            <div class="example-contents"><p>
                At its most basic, you simply initialize and register the
                <em class="emphasis">ViewRenderer</em> helper with the helper broker in your
                bootstrap, and then set variables in your action methods.
            </p></div>

            <div class="programlisting php"><div class="phpcode"><div class="php" style="font-family: monospace;"><ol><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #808080; font-style: italic;">// In your bootstrap:</span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">Zend_Controller_Action_HelperBroker::<span style="color: #006600;">getStaticHelper</span><span style="color: #66cc66;">(</span><span style="color: #ff0000;">'viewRenderer'</span><span style="color: #66cc66;">)</span>;</div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">...</div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #808080; font-style: italic;">// 'foo' module, 'bar' controller:</span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #000000; font-weight: bold;">class</span> Foo_BarController <span style="color: #000000; font-weight: bold;">extends</span> Zend_Controller_Action</div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #66cc66;">{</span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #808080; font-style: italic;">// Render bar/index.phtml by default; no action required</span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> indexAction<span style="color: #66cc66;">(</span><span style="color: #66cc66;">)</span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #66cc66;">{</span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #66cc66;">}</span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #808080; font-style: italic;">// Render bar/populate.phtml with variable 'foo' set to 'bar'.</span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #808080; font-style: italic;">// Since view object defined at preDispatch(), it's already available.</span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> populateAction<span style="color: #66cc66;">(</span><span style="color: #66cc66;">)</span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #66cc66;">{</span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000ff;">$this</span>-&gt;<span style="color: #006600;">view</span>-&gt;<span style="color: #006600;">foo</span> = <span style="color: #ff0000;">'bar'</span>;</div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #66cc66;">}</span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #808080; font-style: italic;">// Renders nothing as it forwards to another action; the new action</span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #808080; font-style: italic;">// will perform any rendering</span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> bazAction<span style="color: #66cc66;">(</span><span style="color: #66cc66;">)</span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #66cc66;">{</span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000ff;">$this</span>-&gt;_forward<span style="color: #66cc66;">(</span><span style="color: #ff0000;">'index'</span><span style="color: #66cc66;">)</span>;</div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #66cc66;">}</span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #808080; font-style: italic;">// Renders nothing as it redirects to another location</span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> batAction<span style="color: #66cc66;">(</span><span style="color: #66cc66;">)</span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #66cc66;">{</span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000ff;">$this</span>-&gt;_redirect<span style="color: #66cc66;">(</span><span style="color: #ff0000;">'/index'</span><span style="color: #66cc66;">)</span>;</div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #66cc66;">}</span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #66cc66;">}</span></div></li></ol></div></div></div>

        </div>

        <blockquote><p><b class="note">Note</b>: <span class="info"><b>Naming Conventions: Word Delimiters in Controller and Action Names</b><br></span>
            

            
                If your controller or action name is composed of several
                words, the dispatcher requires that these are separated on
                the <acronym class="acronym">URL</acronym> by specific path and word delimiter characters. The
                <em class="emphasis">ViewRenderer</em> replaces any path delimiter found
                in the controller name with an actual path delimiter ('/'),
                and any word delimiter found with a dash ('-') when creating
                paths. Thus, a call to the action
                <var class="filename">/foo.bar/baz.bat</var> would dispatch to
                 <span class="methodname">FooBarController::bazBatAction()</span> in
                <var class="filename">FooBarController.php</var>, which would render
                <var class="filename">foo-bar/baz-bat.phtml</var>; a call to the action
                <var class="filename">/bar_baz/baz-bat</var> would dispatch to
                 <span class="methodname">Bar_BazController::bazBatAction()</span> in
                <var class="filename">Bar/BazController.php</var> (note the path
                separation) and render <var class="filename">bar/baz/baz-bat.phtml</var>.
            <br>

            
                Note that the in the second example, the module is still the
                default module, but that, because of the existence of a path
                separator, the controller receives the name
                <span class="classname">Bar_BazController</span>, in
                <var class="filename">Bar/BazController.php</var>. The ViewRenderer mimics
                the controller directory hierarchy.
            <br></p></blockquote>

        <div class="example"><div class="info"><p><b>Example #10 Disabling Autorender</b></p></div>
            

            <div class="example-contents"><p>
                For some actions or controllers, you may want to turn off the
                autorendering -- for instance, if you're wanting to emit a
                different type of output (<acronym class="acronym">XML</acronym>, <acronym class="acronym">JSON</acronym>, etc),
                or if you simply want
                to emit nothing. You have two options: turn off all cases of
                autorendering ( <span class="methodname">setNeverRender()</span>), or simply turn it
                off for the current action ( <span class="methodname">setNoRender()</span>).
            </p></div>

            <div class="programlisting php"><div class="phpcode"><div class="php" style="font-family: monospace;"><ol><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #808080; font-style: italic;">// Baz controller class, bar module:</span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #000000; font-weight: bold;">class</span> Bar_BazController <span style="color: #000000; font-weight: bold;">extends</span> Zend_Controller_Action</div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #66cc66;">{</span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> fooAction<span style="color: #66cc66;">(</span><span style="color: #66cc66;">)</span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #66cc66;">{</span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080; font-style: italic;">// Don't auto render this action</span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000ff;">$this</span>-&gt;_helper-&gt;<span style="color: #006600;">viewRenderer</span>-&gt;<span style="color: #006600;">setNoRender</span><span style="color: #66cc66;">(</span><span style="color: #66cc66;">)</span>;</div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #66cc66;">}</span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #66cc66;">}</span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #808080; font-style: italic;">// Bat controller class, bar module:</span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #000000; font-weight: bold;">class</span> Bar_BatController <span style="color: #000000; font-weight: bold;">extends</span> Zend_Controller_Action</div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #66cc66;">{</span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> preDispatch<span style="color: #66cc66;">(</span><span style="color: #66cc66;">)</span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #66cc66;">{</span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080; font-style: italic;">// Never auto render this controller's actions</span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000ff;">$this</span>-&gt;_helper-&gt;<span style="color: #006600;">viewRenderer</span>-&gt;<span style="color: #006600;">setNoRender</span><span style="color: #66cc66;">(</span><span style="color: #66cc66;">)</span>;</div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #66cc66;">}</span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #66cc66;">}</span></div></li></ol></div></div></div>

        </div>

        <blockquote><p><b class="note">Note</b>: 
            
                In most cases, it makes no sense to turn off autorendering
                globally (ala  <span class="methodname">setNeverRender()</span>), as the only thing
                you then gain from <em class="emphasis">ViewRenderer</em> is the autosetup of
                the view object.
            <br></p></blockquote>

        <div class="example"><div class="info"><p><b>Example #11 Choosing a Different View Script</b></p></div>
            

            <div class="example-contents"><p>
                Some situations require that you render a different script than
                one named after the action. For instance, if you have a
                controller that has both add and edit actions, they may both
                display the same 'form' view, albeit with different values set.
                You can easily change the script name used with either
                 <span class="methodname">setScriptAction()</span>,  <span class="methodname">setRender()</span>,
                or calling the helper as a method, which will invoke
                 <span class="methodname">setRender()</span>.
            </p></div>

            <div class="programlisting php"><div class="phpcode"><div class="php" style="font-family: monospace;"><ol><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #808080; font-style: italic;">// Bar controller class, foo module:</span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #000000; font-weight: bold;">class</span> Foo_BarController <span style="color: #000000; font-weight: bold;">extends</span> Zend_Controller_Action</div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #66cc66;">{</span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> addAction<span style="color: #66cc66;">(</span><span style="color: #66cc66;">)</span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #66cc66;">{</span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080; font-style: italic;">// Render 'bar/form.phtml' instead of 'bar/add.phtml'</span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000ff;">$this</span>-&gt;_helper-&gt;<span style="color: #006600;">viewRenderer</span><span style="color: #66cc66;">(</span><span style="color: #ff0000;">'form'</span><span style="color: #66cc66;">)</span>;</div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #66cc66;">}</span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> editAction<span style="color: #66cc66;">(</span><span style="color: #66cc66;">)</span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #66cc66;">{</span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080; font-style: italic;">// Render 'bar/form.phtml' instead of 'bar/edit.phtml'</span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000ff;">$this</span>-&gt;_helper-&gt;<span style="color: #006600;">viewRenderer</span>-&gt;<span style="color: #006600;">setScriptAction</span><span style="color: #66cc66;">(</span><span style="color: #ff0000;">'form'</span><span style="color: #66cc66;">)</span>;</div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #66cc66;">}</span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> processAction<span style="color: #66cc66;">(</span><span style="color: #66cc66;">)</span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #66cc66;">{</span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080; font-style: italic;">// do some validation...</span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">if</span> <span style="color: #66cc66;">(</span>!<span style="color: #0000ff;">$valid</span><span style="color: #66cc66;">)</span> <span style="color: #66cc66;">{</span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080; font-style: italic;">// Render 'bar/form.phtml' instead of 'bar/process.phtml'</span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000ff;">$this</span>-&gt;_helper-&gt;<span style="color: #006600;">viewRenderer</span>-&gt;<span style="color: #006600;">setRender</span><span style="color: #66cc66;">(</span><span style="color: #ff0000;">'form'</span><span style="color: #66cc66;">)</span>;</div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">return</span>;</div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">}</span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080; font-style: italic;">// otherwise continue processing...</span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #66cc66;">}</span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #66cc66;">}</span></div></li></ol></div></div></div>

        </div>

        <div class="example"><div class="info"><p><b>Example #12 Modifying the Registered View</b></p></div>
            

            <div class="example-contents"><p>
                What if you need to modify the view object -- for instance,
                change the helper paths, or the encoding? You can do so either
                by modifying the view object set in your controller, or by
                grabbing the view object out of the <em class="emphasis">ViewRenderer</em>;
                both are references to the same object.
            </p></div>

            <div class="programlisting php"><div class="phpcode"><div class="php" style="font-family: monospace;"><ol><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #808080; font-style: italic;">// Bar controller class, foo module:</span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #000000; font-weight: bold;">class</span> Foo_BarController <span style="color: #000000; font-weight: bold;">extends</span> Zend_Controller_Action</div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #66cc66;">{</span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> preDispatch<span style="color: #66cc66;">(</span><span style="color: #66cc66;">)</span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #66cc66;">{</span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080; font-style: italic;">// change view encoding</span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000ff;">$this</span>-&gt;<span style="color: #006600;">view</span>-&gt;<span style="color: #006600;">setEncoding</span><span style="color: #66cc66;">(</span><span style="color: #ff0000;">'UTF-8'</span><span style="color: #66cc66;">)</span>;</div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #66cc66;">}</span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> bazAction<span style="color: #66cc66;">(</span><span style="color: #66cc66;">)</span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #66cc66;">{</span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080; font-style: italic;">// Get view object and set escape callback to 'htmlspecialchars'</span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000ff;">$view</span> = <span style="color: #0000ff;">$this</span>-&gt;_helper-&gt;<span style="color: #006600;">viewRenderer</span>-&gt;<span style="color: #006600;">view</span>;</div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000ff;">$view</span>-&gt;<span style="color: #006600;">setEscape</span><span style="color: #66cc66;">(</span><span style="color: #ff0000;">'htmlspecialchars'</span><span style="color: #66cc66;">)</span>;</div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #66cc66;">}</span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #66cc66;">}</span></div></li></ol></div></div></div>

        </div>
    </div>

    <div class="section" id="zend.controller.actionhelper.viewrenderer.advancedusage" name="zend.controller.actionhelper.viewrenderer.advancedusage"><div class="info"><h4>Advanced Usage Examples</h4></div>
        

        <div class="example"><div class="info"><p><b>Example #13 Changing the Path Specifications</b></p></div>
            

            <div class="example-contents"><p>
                In some circumstances, you may decide that the default path
                specifications do not fit your site's needs. For instance, you
                may want to have a single template tree to which you may then
                give access to your designers (this is very typical when using
                <a href="http://smarty.php.net/" class="link external">» Smarty</a>, for
                instance). In such a case, you may want to hardcode the view
                base path specification, and create an alternate specification
                for the action view script paths themselves.
            </p></div>

            <div class="example-contents"><p>
                For purposes of this example, let's assume that the base path to
                views should be '<var class="filename">/opt/vendor/templates</var>', and that you wish for
                view scripts to be referenced by
                '<var class="filename">:moduleDir/:controller/:action.:suffix</var>'; if the
                <em class="emphasis">noController</em>
                flag has been set, you want to render out of the top level
                instead of in a subdirectory ('<var class="filename">:action.:suffix</var>'). Finally, you
                want to use 'tpl' as the view script filename suffix.
            </p></div>

            <div class="programlisting php"><div class="phpcode"><div class="php" style="font-family: monospace;"><ol><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #808080; font-style: italic;">/**</span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #808080; font-style: italic;"> * In your bootstrap:</span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #808080; font-style: italic;"> */</span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #808080; font-style: italic;">// Different view implementation</span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #0000ff;">$view</span> = <span style="color: #000000; font-weight: bold;">new</span> ZF_Smarty<span style="color: #66cc66;">(</span><span style="color: #66cc66;">)</span>;</div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #0000ff;">$viewRenderer</span> = <span style="color: #000000; font-weight: bold;">new</span> Zend_Controller_Action_Helper_ViewRenderer<span style="color: #66cc66;">(</span><span style="color: #0000ff;">$view</span><span style="color: #66cc66;">)</span>;</div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #0000ff;">$viewRenderer</span>-&gt;<span style="color: #006600;">setViewBasePathSpec</span><span style="color: #66cc66;">(</span><span style="color: #ff0000;">'/opt/vendor/templates'</span><span style="color: #66cc66;">)</span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;-&gt;<span style="color: #006600;">setViewScriptPathSpec</span><span style="color: #66cc66;">(</span><span style="color: #ff0000;">':module/:controller/:action.:suffix'</span><span style="color: #66cc66;">)</span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;-&gt;<span style="color: #006600;">setViewScriptPathNoControllerSpec</span><span style="color: #66cc66;">(</span><span style="color: #ff0000;">':action.:suffix'</span><span style="color: #66cc66;">)</span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;-&gt;<span style="color: #006600;">setViewSuffix</span><span style="color: #66cc66;">(</span><span style="color: #ff0000;">'tpl'</span><span style="color: #66cc66;">)</span>;</div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">Zend_Controller_Action_HelperBroker::<span style="color: #006600;">addHelper</span><span style="color: #66cc66;">(</span><span style="color: #0000ff;">$viewRenderer</span><span style="color: #66cc66;">)</span>;</div></li></ol></div></div></div>

        </div>

        <div class="example"><div class="info"><p><b>Example #14 Rendering Multiple View Scripts from a Single Action</b></p></div>
            

            <div class="example-contents"><p>
                At times, you may need to render multiple view scripts from a
                single action. This is very straightforward -- simply make
                multiple calls to  <span class="methodname">render()</span>:
            </p></div>

            <div class="programlisting php"><div class="phpcode"><div class="php" style="font-family: monospace;"><ol><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #000000; font-weight: bold;">class</span> SearchController <span style="color: #000000; font-weight: bold;">extends</span> Zend_Controller_Action</div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #66cc66;">{</span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> resultsAction<span style="color: #66cc66;">(</span><span style="color: #66cc66;">)</span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #66cc66;">{</span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080; font-style: italic;">// Assume $this-&gt;model is the current model</span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000ff;">$this</span>-&gt;<span style="color: #006600;">view</span>-&gt;<span style="color: #006600;">results</span> =</div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000ff;">$this</span>-&gt;<span style="color: #006600;">model</span>-&gt;<span style="color: #006600;">find</span><span style="color: #66cc66;">(</span><span style="color: #0000ff;">$this</span>-&gt;_getParam<span style="color: #66cc66;">(</span><span style="color: #ff0000;">'query'</span>, <span style="color: #ff0000;">''</span><span style="color: #66cc66;">)</span>;</div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080; font-style: italic;">// render() by default proxies to the ViewRenderer</span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080; font-style: italic;">// Render first the search form and then the results</span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000ff;">$this</span>-&gt;<span style="color: #006600;">render</span><span style="color: #66cc66;">(</span><span style="color: #ff0000;">'form'</span><span style="color: #66cc66;">)</span>;</div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000ff;">$this</span>-&gt;<span style="color: #006600;">render</span><span style="color: #66cc66;">(</span><span style="color: #ff0000;">'results'</span><span style="color: #66cc66;">)</span>;</div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #66cc66;">}</span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> formAction<span style="color: #66cc66;">(</span><span style="color: #66cc66;">)</span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #66cc66;">{</span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080; font-style: italic;">// do nothing; ViewRenderer autorenders the view script</span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #66cc66;">}</span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #66cc66;">}</span></div></li></ol></div></div></div>

        </div>
    </div>
</div>
    </div>

    <div class="section" id="zend.controller.actionhelper.writingyourown" name="zend.controller.actionhelper.writingyourown"><div class="info"><h2>Writing Your Own Helpers</h2></div>
        

        <p class="para">
            Action helpers extend
            <span class="classname">Zend_Controller_Action_Helper_Abstract</span>, an abstract
            class that provides the basic interface and functionality required
            by the helper broker. These include the following methods:
        </p>

        <ul class="itemizedlist"><li class="listitem">
                <p class="para">
                     <span class="methodname">setActionController()</span> is used to set the current
                    action controller.
                </p>
            </li>

            <li class="listitem">
                <p class="para">
                     <span class="methodname">init()</span>, triggered by the helper broker at
                    instantiation, can be used to trigger initialization in the
                    helper; this can be useful for resetting state when multiple
                    controllers use the same helper in chained actions.
                </p>
            </li>

            <li class="listitem">
                <p class="para">
                     <span class="methodname">preDispatch()</span>, is triggered prior to a
                    dispatched action.
                </p>
            </li>

            <li class="listitem">
                <p class="para">
                     <span class="methodname">postDispatch()</span> is triggered when a dispatched
                    action is done -- even if a  <span class="methodname">preDispatch()</span>
                    plugin has skipped the action. Mainly useful for cleanup.
                </p>
            </li>

            <li class="listitem">
                <p class="para">
                     <span class="methodname">getRequest()</span> retrieves the current request
                    object.
                </p>
            </li>

            <li class="listitem">
                <p class="para">
                     <span class="methodname">getResponse()</span> retrieves the current response
                    object.
                </p>
            </li>

            <li class="listitem">
                <p class="para">
                     <span class="methodname">getName()</span> retrieves the helper name. It
                    retrieves the portion of the class name following the last
                    underscore character, or the full class name otherwise. As
                    an example, if the class is named
                    <span class="classname">Zend_Controller_Action_Helper_Redirector</span>, it
                    will return <em class="emphasis">Redirector</em>; a class named
                    <em class="emphasis">FooMessage</em> will simply return itself.
                </p>
            </li>
        </ul><p class="para">
            You may optionally include a  <span class="methodname">direct()</span> method in your
            helper class. If defined, it allows you to treat the helper as a
            method of the helper broker, in order to allow easy, one-off usage
            of the helper. As an example, the <a href="http://framework.zend.com/manual/1.12/en/zend.controller.actionhelpers.html#zend.controller.actionhelpers.redirector" class="link">redirector</a>
            defines  <span class="methodname">direct()</span> as an alias of
             <span class="methodname">goto()</span>, allowing use of the helper like this:
        </p>

        <div class="programlisting php"><div class="phpcode"><div class="php" style="font-family: monospace;"><ol><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #808080; font-style: italic;">// Redirect to /blog/view/item/id/42</span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #0000ff;">$this</span>-&gt;_helper-&gt;<span style="color: #006600;">redirector</span><span style="color: #66cc66;">(</span><span style="color: #ff0000;">'item'</span>, <span style="color: #ff0000;">'view'</span>, <span style="color: #ff0000;">'blog'</span>, <a href="http://www.php.net/array"><span style="color: #000066;">array</span></a><span style="color: #66cc66;">(</span><span style="color: #ff0000;">'id'</span> =&gt; <span style="color: #cc66cc;">42</span><span style="color: #66cc66;">)</span><span style="color: #66cc66;">)</span>;</div></li></ol></div></div></div>


        <p class="para">
            Internally, the helper broker's  <span class="methodname">__call()</span> method looks
            for a helper named <em class="emphasis">redirector</em>, then checks to see if
            that helper has a defined  <span class="methodname">direct()</span> method, and calls it
            with the arguments provided.
        </p>

        <p class="para">
            Once you have created your own helper class, you may provide access
            to it as described in the sections above.
        </p>
    </div>
</div><div class="related hide-on-print"><ul><li class="prev"><a href="http://framework.zend.com/manual/1.12/en/zend.controller.action.html">Action Controllers</a></li><li class="next"><a href="http://framework.zend.com/manual/1.12/en/zend.controller.response.html">The Response Object</a></li></ul></div>    <div id="disqus_thread"><iframe verticalscrolling="no" horizontalscrolling="no" src="zend.controller.actionhelpers_files/a.html" style="width: 100%; border: medium none; overflow: hidden; height: 987px;" role="complementary" allowtransparency="true" data-disqus-uid="1" id="dsq1" frameborder="0" scrolling="no" width="100%"></iframe><iframe src="zend.controller.actionhelpers_files/client.html" style="width: 100%; border: medium none; overflow: hidden; display: none;" role="application" allowtransparency="true" data-disqus-uid="3" id="dsq3" frameborder="0" width="100%"></iframe><iframe style="width: 893px; border: medium none; overflow: hidden; top: 0px; min-width: 893px; max-width: 893px; position: fixed; max-height: 29px; min-height: 29px; height: 29px; display: none;" role="alert" allowtransparency="true" data-disqus-uid="-indicator-north" id="dsq-indicator-north" frameborder="0" scrolling="no"></iframe><iframe style="width: 893px; border: medium none; overflow: hidden; bottom: 0px; min-width: 893px; max-width: 893px; position: fixed; max-height: 29px; min-height: 29px; height: 29px; display: none;" role="alert" allowtransparency="true" data-disqus-uid="-indicator-south" id="dsq-indicator-south" frameborder="0" scrolling="no"></iframe></div>
    <script type="text/javascript">
        var disqus_developer = 0;
        var disqus_shortname = 'zfmanual';
        var disqus_identifier = 'zfmanual-zend.controller.actionhelpers.html';
        var disqus_url = 'http://framework.zend.com/manual/1.12/en/zend.controller.actionhelpers.html';
        var disqus_title = 'Action Helpers - Zend_Controller';

        /* * * DON'T EDIT BELOW THIS LINE * * */
        (function() {
            var dsq = document.createElement('script'); dsq.type = 'text/javascript'; dsq.async = true;
            dsq.src = 'http://' + disqus_shortname + '.disqus.com/embed.js';
            (document.getElementsByTagName('head')[0] || document.getElementsByTagName('body')[0]).appendChild(dsq);
        })();
    </script>
    <noscript>Please enable JavaScript to view the <a href="http://disqus.com/?ref_noscript">comments powered by Disqus.</a></noscript>
                    </div>
            </div>
        
        <!-- Footer -->
        <footer id="footer">
            <div class="row">
                <div class="two mobile-two columns">
                    <h4>About</h4>
                    <ul>
                        <li class="link-highlight"><a href="http://framework.zend.com/about/">Overview</a></li>
                        <li><a href="http://framework.zend.com/about/faq/">ZF2 FAQ</a></li>
                        <li><a href="http://framework.zend.com/about/faq-v1/">ZF1 FAQ</a></li>

                                                <li><a href="http://framework.zend.com/security/">Security</a></li>
                        <li><a href="http://framework.zend.com/changelog/">Changelog</a></li>
                        <li><a href="http://framework.zend.com/blog/index.html">Blog</a></li>
                    </ul>
                </div>

                <div class="two mobile-two columns">
                    <h4>Learn</h4>
                    <ul>
                        <li><a href="http://framework.zend.com/manual/2.1/en/user-guide/overview.html">User Guide</a></li>
                        <li><a href="http://framework.zend.com/manual/2.1/en/index.html">Reference Guide</a></li>
                        <li><a href="http://framework.zend.com/docs/api/">APIs</a></li>
                        <!--              <li><a href="">Webinars</a></li>-->
                        <li><a href="http://framework.zend.com/learn/training-and-certification/">Training &amp; Certification</a></li>
                        <li><a href="http://framework.zend.com/learn/support-and-consulting/">Support &amp; Consulting</a></li>
                    </ul>
                </div>

                <hr>

                <div class="two mobile-two columns">
                    <h4>Get Started</h4>
                    <ul>
                        <li><a href="http://framework.zend.com/downloads">Downloads</a></li>
                        <li><a href="http://framework.zend.com/downloads/skeleton-app">Get the Skeleton App</a></li>
                        <li><a href="http://framework.zend.com/downloads/phpcloud">Try on <span class="link-highlight">phpcloud.com</span></a></li>
                    </ul>
                </div>

                <div class="two mobile-two columns">
                    <h4>Participate</h4>
                    <ul>
                        <li><a href="http://framework.zend.com/participate/">Overview</a></li>
                        <li><a href="http://framework.zend.com/participate/contributor-guide/">Contributors Guide</a></li>
                                                <li><a href="http://framework.zend.com/participate/blogs/">Blogs</a></li>
                                            </ul>
                </div>

                <div class="two mobile-four columns offset-by-two" id="contact-menu">
                    <h4>Contact Us</h4>
                    <ul>
                        <li><a href="http://framework.zend.com/contact">form</a></li>
                        <li><a href="http://framework.zend.com/archives/">mailing lists</a></li>
                        <li><a href="http://framework.zend.com/irc/">IRC</a></li>
                    </ul>
                </div>
            </div>

            <div class="row">
                <ul id="social-links" class="block-grid four-up mobile-two-up">
                    <li>
                        <a href="https://github.com/zendframework/zf2">
                            <i class="foundicon-github"></i>
                        </a>
                    </li>
                    <li>
                        <a href="https://twitter.com/zfdevteam">
                            <i class="foundicon-twitter"></i>
                        </a>
                    </li>
                    <li>
                        <a href="http://framework.zend.com/blog/feed-rss.xml">
                            <i class="foundicon-rss blog"></i>
                        </a>
                    </li>
                    <li>
                        <a href="http://framework.zend.com/security/feed/">
                            <i class="foundicon-rss security"></i>
                        </a>
                    </li>
                </ul>
            </div>

            <div id="footer-copyright" class="row">
                <p>© 2006 - 2013 by Zend Technologies Ltd. All rights reserved.</p>
                <a href="#header" id="to_top">
                    <img src="zend.controller.actionhelpers_files/arrow.png" alt="" title="back to top" height="20" width="22">
                </a>
            </div>
        </footer>

        <!-- Included JS Files -->
        <script type="text/javascript" src="zend.controller.actionhelpers_files/jquery.js"></script>
        <script type="text/javascript" src="zend.controller.actionhelpers_files/foundation.js"></script>
        <script type="text/javascript" src="zend.controller.actionhelpers_files/app.js"></script>

        <!-- Initialize JS Plugins -->
        <script>
            $(document).foundationNavigation();
        </script>
        
        <!-- Google Analytics -->
        <script type="text/javascript">
            function setCustomVar() {
                var t = _gat._getTrackerByName();
                if (t._getVisitorCustomVar(1) === undefined) {
                    t._setCustomVar(1, 'subdomains', '<value:framework>', 2);
                }
            }
            var _gaq = _gaq || [];
            _gaq.push(['_setAccount', 'UA-291885-1']);
            _gaq.push(['_setDomainName', '.zend.com']);
            _gaq.push(setCustomVar);
            _gaq.push(['_trackPageview']);

            (function() {
                var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
                ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
                (document.getElementsByTagName('head')[0] || document.getElementsByTagName('body')[0]).appendChild(ga);
            })();

            var google_conversion_id = 1072138399;
            var google_conversion_label = "PTX5CIfdwAMQn5Ge_wM";
            var google_custom_params = window.google_tag_params;
            var google_remarketing_only = true;
        </script>

        <!-- Eloqua integration -->
        <script type="text/javascript" src="zend.controller.actionhelpers_files/elqCfg.js"></script>
        <script type="text/javascript" src="zend.controller.actionhelpers_files/elqImg.js"></script><layer hidden="true"><img src="zend.controller.actionhelpers_files/svrGP.gif" border="0" height="1" width="1"></layer>
        <script type="text/javascript" src="zend.controller.actionhelpers_files/conversion.js"></script><iframe name="google_conversion_frame" src="zend.controller.actionhelpers_files/a_002.html" marginwidth="0" marginheight="0" vspace="0" hspace="0" allowtransparency="true" frameborder="0" height="13" scrolling="no" width="300">&lt;img
 height="1" width="1" border="0" 
src="http://googleads.g.doubleclick.net/pagead/viewthroughconversion/1072138399/?frame=0&amp;random=1366125264999&amp;cv=7&amp;fst=1366125264999&amp;num=1&amp;fmt=1&amp;label=PTX5CIfdwAMQn5Ge_wM&amp;guid=ON&amp;u_h=768&amp;u_w=1360&amp;u_ah=744&amp;u_aw=1295&amp;u_cd=24&amp;u_his=2&amp;u_tz=420&amp;u_java=false&amp;u_nplug=6&amp;u_nmime=44&amp;ref=http%3A//www.google.com/url%3Fsa%3Dt%26rct%3Dj%26q%3D%26esrc%3Ds%26source%3Dweb%26cd%3D2%26ved%3D0CEUQFjAB%26url%3Dhttp%253A%252F%252Fframework.zend.com%252Fmanual%252F1.12%252Fen%252Fzend.controller.actionhelpers.html%26ei%3DmGptUfaFOemViQeciIHQCQ%26usg%3DAFQjCNHGct5mzoSElk1y75BVWfTUEYXwBA%26sig2%3D4Q-_pJRS4OlDP1S&amp;url=http%3A//framework.zend.com/manual/1.12/en/zend.controller.actionhelpers.html&amp;frm=0"
 /&gt;</iframe>
        <noscript>
            <div style="display: inline;">
                <img height="1" width="1" style="border-style:none;" alt="" src="http://googleads.g.doubleclick.net/pagead/viewthroughconversion/1072138399/?value=0&amp;label=PTX5CIfdwAMQn5Ge_wM&amp;guid=ON&amp;script=0">
            </div>
        </noscript>

        <!-- LivePerson integration -->
        <script type="text/javascript">
            var lpMTagConfig = {'lpServer' : "server.iad.liveperson.net",'lpNumber' : "10919998",'lpProtocol' : "https"}; function lpAddMonitorTag(src){if(typeof(src)=='undefined'||typeof(src)=='object'){src=lpMTagConfig.lpMTagSrc?lpMTagConfig.lpMTagSrc:'/hcp/html/mTag.js';}if(src.indexOf('http')!=0){src=lpMTagConfig.lpProtocol+"://"+lpMTagConfig.lpServer+src+'?site='+lpMTagConfig.lpNumber;}else{if(src.indexOf('site=')<0){if(src.indexOf('?')<0)src=src+'?';else src=src+'&';src=src+'site='+lpMTagConfig.lpNumber;}};var s=document.createElement('script');s.setAttribute('type','text/javascript');s.setAttribute('charset','iso-8859-1');s.setAttribute('src',src);document.getElementsByTagName('head').item(0).appendChild(s);} if (window.attachEvent) window.attachEvent('onload',lpAddMonitorTag); else window.addEventListener("load",lpAddMonitorTag,false);
        </script>
    

</body></html>